diff --git a/cmake/ConkyBuildOptions.cmake b/cmake/ConkyBuildOptions.cmake
index bf89dc15a..e9584c9db 100644
--- a/cmake/ConkyBuildOptions.cmake
+++ b/cmake/ConkyBuildOptions.cmake
@@ -63,6 +63,12 @@ if (NOT LIB_INSTALL_DIR)
endif (NOT LIB_INSTALL_DIR)
set(PACKAGE_LIBRARY_DIR "${LIB_INSTALL_DIR}/conky" CACHE STRING "Package library path (where Lua bindings are installed" FORCE)
set(DEFAULTNETDEV "eth0" CACHE STRING "Default networkdevice")
+
+# Mac only override
+if(OS_DARWIN)
+ set(DEFAULTNETDEV "en0" CACHE STRING "Default networkdevice" FORCE)
+endif(OS_DARWIN)
+
set(XDG_CONFIG_FILE "$HOME/.config/conky/conky.conf" CACHE STRING "Configfile of the user (XDG)")
set(CONFIG_FILE "$HOME/.conkyrc" CACHE STRING "Configfile of the user")
set(MAX_USER_TEXT_DEFAULT "16384" CACHE STRING "Default maximum size of config TEXT buffer, i.e. below TEXT line.")
@@ -76,7 +82,6 @@ if(OS_LINUX)
option(BUILD_PORT_MONITORS "Build TCP portmon support" true)
option(BUILD_IBM "Support for IBM/Lenovo notebooks" true)
option(BUILD_HDDTEMP "Support for hddtemp" true)
- option(BUILD_WLAN "Enable wireless support" false)
# nvidia may also work on FreeBSD, not sure
option(BUILD_NVIDIA "Enable nvidia support" false)
option(BUILD_IPV6 "Enable if you want IPv6 support" true)
@@ -84,14 +89,20 @@ else(OS_LINUX)
set(BUILD_PORT_MONITORS false)
set(BUILD_IBM false)
set(BUILD_HDDTEMP false)
- set(BUILD_WLAN false)
set(BUILD_NVIDIA false)
set(BUILD_IPV6 false)
endif(OS_LINUX)
+# macOS Only
+if(OS_DARWIN)
+ option(BUILD_IPGFREQ "Enable cpu freq calculation based on IntelĀ® Power Gadget; otherwise use constant factory value" false)
+endif(OS_DARWIN)
+
# Optional features etc
#
+option(BUILD_WLAN "Enable wireless support" false)
+
option(BUILD_BUILTIN_CONFIG "Enable builtin default configuration" true)
option(BUILD_IOSTATS "Enable disk I/O stats" true)
@@ -110,7 +121,14 @@ endif(BUILD_NCURSES)
option(BUILD_X11 "Build X11 support" true)
if(BUILD_X11)
option(OWN_WINDOW "Enable own_window support" true)
- option(BUILD_XDAMAGE "Build Xdamage support" true)
+
+ # Mac Fix
+ if(OS_DARWIN)
+ option(BUILD_XDAMAGE "Build Xdamage support" false)
+ else(OS_DARWIN)
+ option(BUILD_XDAMAGE "Build Xdamage support" true)
+ endif(OS_DARWIN)
+
option(BUILD_XINERAMA "Build Xinerama support" true)
option(BUILD_XDBE "Build Xdbe (double-buffer) support" true)
option(BUILD_XFT "Build Xft (freetype fonts) support" true)
diff --git a/cmake/ConkyPlatformChecks.cmake b/cmake/ConkyPlatformChecks.cmake
index 39bef3d45..d926aa81d 100644
--- a/cmake/ConkyPlatformChecks.cmake
+++ b/cmake/ConkyPlatformChecks.cmake
@@ -137,6 +137,16 @@ if(BUILD_NCURSES AND OS_DARWIN)
set(conky_libs ${conky_libs} -lncurses)
endif(BUILD_NCURSES AND OS_DARWIN)
+if(BUILD_WLAN AND OS_DARWIN)
+ find_library(CW CoreWLAN)
+ set(conky_libs ${conky_libs} ${CW})
+endif(BUILD_WLAN AND OS_DARWIN)
+
+if(OS_DARWIN AND BUILD_IPGFREQ)
+ find_library(IPG IntelPowerGadget)
+ set(conky_libs ${conky_libs} ${IPG})
+endif(OS_DARWIN AND BUILD_IPGFREQ)
+
if(BUILD_MATH)
set(conky_libs ${conky_libs} -lm)
endif(BUILD_MATH)
@@ -198,7 +208,7 @@ if(BUILD_MYSQL)
set(conky_libs ${conky_libs} ${MYSQLCLIENT_LIB})
endif(BUILD_MYSQL)
-if(BUILD_WLAN)
+if(BUILD_WLAN AND OS_LINUX)
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
check_include_files(iwlib.h IWLIB_H)
if(NOT IWLIB_H)
@@ -210,7 +220,7 @@ if(BUILD_WLAN)
endif(NOT IWLIB_LIB)
set(conky_libs ${conky_libs} ${IWLIB_LIB})
check_function_exists(iw_sockets_open IWLIB_SOCKETS_OPEN_FUNC)
-endif(BUILD_WLAN)
+endif(BUILD_WLAN AND OS_LINUX)
if(BUILD_PORT_MONITORS)
check_function_exists(getnameinfo HAVE_GETNAMEINFO)
diff --git a/cmake/config.h.in b/cmake/config.h.in
index 8bd09725f..8a442bbe0 100644
--- a/cmake/config.h.in
+++ b/cmake/config.h.in
@@ -102,6 +102,8 @@
#cmakedefine BUILD_IOSTATS 1
+#cmakedefine BUILD_IPGFREQ 0
+
#cmakedefine BUILD_WLAN 1
#cmakedefine BUILD_ICAL 1
diff --git a/data/conky.conf b/data/conky.conf
index b3709c8d0..c515a5f95 100644
--- a/data/conky.conf
+++ b/data/conky.conf
@@ -72,7 +72,7 @@ $hr
${color grey}File systems:
/ $color${fs_used /}/${fs_size /} ${fs_bar 6 /}
${color grey}Networking:
-Up:$color ${upspeed eth0} ${color grey} - Down:$color ${downspeed eth0}
+Up:$color ${upspeed} ${color grey} - Down:$color ${downspeed}
$hr
${color grey}Name PID CPU% MEM%
${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}
diff --git a/data/conky_no_x11.conf b/data/conky_no_x11.conf
index 40a675da2..bfd3a9a20 100644
--- a/data/conky_no_x11.conf
+++ b/data/conky_no_x11.conf
@@ -46,7 +46,7 @@ Processes: $processes Running: $running_processes
File systems:
/ ${fs_used /}/${fs_size /} ${fs_bar 6 /}
Networking:
-Up: ${upspeed eth0} - Down: ${downspeed eth0}
+Up: ${upspeed} - Down: ${downspeed}
Name PID CPU% MEM%
${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}
${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}
diff --git a/doc/variables.xml b/doc/variables.xml
index 617aa8404..0b6564b6a 100644
--- a/doc/variables.xml
+++ b/doc/variables.xml
@@ -4784,7 +4784,7 @@
- WLAN channel on which device 'net' is listening (Linux only)
+ WLAN channel on which device 'net' is listening
@@ -4804,7 +4804,7 @@
- Frequency on which device 'net' is listening (Linux only)
+ Frequency on which device 'net' is listening
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 59d2efbad..4e490ac0c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -135,7 +135,7 @@ endif(OS_HAIKU)
if(OS_DARWIN)
set(darwin
- darwin.cc darwin.h
+ darwin.mm darwin.h
darwin_sip.h
i18n.h
)
diff --git a/src/common.h b/src/common.h
index 8b6407ec0..69ccb9958 100644
--- a/src/common.h
+++ b/src/common.h
@@ -158,6 +158,8 @@ uint8_t battery_percentage(struct text_object *);
void print_battery_short(struct text_object *, char *, int);
#endif /* !__OpenBSD__ */
+void free_cpu(struct text_object *);
+
void print_blink(struct text_object *, char *, int);
void print_include(struct text_object *, char *, int);
diff --git a/src/core.cc b/src/core.cc
index de2f8c075..98d3566c4 100644
--- a/src/core.cc
+++ b/src/core.cc
@@ -484,42 +484,43 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->data.i = atoi(&arg[0]);
}
obj->callbacks.print = &print_voltage_v;
+
+#endif /* __linux__ */
#ifdef BUILD_WLAN
- END OBJ(wireless_essid, &update_net_stats) obj->data.opaque =
- get_net_stat(arg, obj, free_at_crash);
- obj->callbacks.print = &print_wireless_essid;
- END OBJ(wireless_channel, &update_net_stats)
- parse_net_stat_arg(obj, arg, free_at_crash);
- obj->callbacks.print = &print_wireless_channel;
- END OBJ(wireless_freq, &update_net_stats)
- parse_net_stat_arg(obj, arg, free_at_crash);
- obj->callbacks.print = &print_wireless_frequency;
- END OBJ(wireless_mode, &update_net_stats)
- parse_net_stat_arg(obj, arg, free_at_crash);
- obj->callbacks.print = &print_wireless_mode;
- END OBJ(wireless_bitrate, &update_net_stats)
- parse_net_stat_arg(obj, arg, free_at_crash);
- obj->callbacks.print = &print_wireless_bitrate;
- END OBJ(wireless_ap, &update_net_stats)
- parse_net_stat_arg(obj, arg, free_at_crash);
- obj->callbacks.print = &print_wireless_ap;
- END OBJ(wireless_link_qual, &update_net_stats)
- parse_net_stat_arg(obj, arg, free_at_crash);
- obj->callbacks.print = &print_wireless_link_qual;
- END OBJ(wireless_link_qual_max, &update_net_stats)
- parse_net_stat_arg(obj, arg, free_at_crash);
- obj->callbacks.print = &print_wireless_link_qual_max;
- END OBJ(wireless_link_qual_perc, &update_net_stats)
- parse_net_stat_arg(obj, arg, free_at_crash);
- obj->callbacks.print = &print_wireless_link_qual_perc;
- END OBJ(wireless_link_bar, &update_net_stats)
- parse_net_stat_bar_arg(obj, arg, free_at_crash);
- obj->callbacks.barval = &wireless_link_barval;
+ END OBJ(wireless_essid, &update_net_stats) obj->data.opaque =
+ get_net_stat(arg, obj, free_at_crash);
+ parse_net_stat_arg(obj, arg, free_at_crash);
+ obj->callbacks.print = &print_wireless_essid;
+ END OBJ(wireless_channel, &update_net_stats)
+ parse_net_stat_arg(obj, arg, free_at_crash);
+ obj->callbacks.print = &print_wireless_channel;
+ END OBJ(wireless_freq, &update_net_stats)
+ parse_net_stat_arg(obj, arg, free_at_crash);
+ obj->callbacks.print = &print_wireless_frequency;
+ END OBJ(wireless_mode, &update_net_stats)
+ parse_net_stat_arg(obj, arg, free_at_crash);
+ obj->callbacks.print = &print_wireless_mode;
+ END OBJ(wireless_bitrate, &update_net_stats)
+ parse_net_stat_arg(obj, arg, free_at_crash);
+ obj->callbacks.print = &print_wireless_bitrate;
+ END OBJ(wireless_ap, &update_net_stats)
+ parse_net_stat_arg(obj, arg, free_at_crash);
+ obj->callbacks.print = &print_wireless_ap;
+ END OBJ(wireless_link_qual, &update_net_stats)
+ parse_net_stat_arg(obj, arg, free_at_crash);
+ obj->callbacks.print = &print_wireless_link_qual;
+ END OBJ(wireless_link_qual_max, &update_net_stats)
+ parse_net_stat_arg(obj, arg, free_at_crash);
+ obj->callbacks.print = &print_wireless_link_qual_max;
+ END OBJ(wireless_link_qual_perc, &update_net_stats)
+ parse_net_stat_arg(obj, arg, free_at_crash);
+ obj->callbacks.print = &print_wireless_link_qual_perc;
+ END OBJ(wireless_link_bar, &update_net_stats)
+ parse_net_stat_bar_arg(obj, arg, free_at_crash);
+ obj->callbacks.barval = &wireless_link_barval;
#endif /* BUILD_WLAN */
-
-#endif /* __linux__ */
-
+
#ifndef __OpenBSD__
END OBJ(acpifan, nullptr) obj->callbacks.print = &print_acpifan;
END OBJ(battery, nullptr) char bat[64];
@@ -673,18 +674,21 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(cpu, &update_cpu_usage) get_cpu_count();
SCAN_CPU(arg, obj->data.i);
obj->callbacks.percentage = &cpu_percentage;
+ obj->callbacks.free = &free_cpu;
DBGP2("Adding $cpu for CPU %d", obj->data.i);
#ifdef BUILD_X11
END OBJ(cpugauge, &update_cpu_usage) get_cpu_count();
SCAN_CPU(arg, obj->data.i);
scan_gauge(obj, arg, 1);
obj->callbacks.gaugeval = &cpu_barval;
+ obj->callbacks.free = &free_cpu;
DBGP2("Adding $cpugauge for CPU %d", obj->data.i);
#endif
END OBJ(cpubar, &update_cpu_usage) get_cpu_count();
SCAN_CPU(arg, obj->data.i);
scan_bar(obj, arg, 1);
obj->callbacks.barval = &cpu_barval;
+ obj->callbacks.free = &free_cpu;
DBGP2("Adding $cpubar for CPU %d", obj->data.i);
#ifdef BUILD_X11
END OBJ(cpugraph, &update_cpu_usage) get_cpu_count();
@@ -694,6 +698,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
DBGP2("Adding $cpugraph for CPU %d", obj->data.i);
free_and_zero(buf);
obj->callbacks.graphval = &cpu_barval;
+ obj->callbacks.free = &free_cpu;
END OBJ(loadgraph, &update_load_average) scan_loadgraph_arg(obj, arg);
obj->callbacks.graphval = &loadgraphval;
#endif /* BUILD_X11 */
diff --git a/src/darwin.h b/src/darwin.h
index 55491228c..d6e6673e7 100644
--- a/src/darwin.h
+++ b/src/darwin.h
@@ -56,4 +56,6 @@ int get_entropy_poolsize(const unsigned int *);
int get_sip_status(void);
void print_sip_status(struct text_object *obj, char *p, int p_max_size);
+void deallocate_cpu_sample(struct text_object *obj);
+
#endif /*DARWIN_H*/
diff --git a/src/darwin.cc b/src/darwin.mm
similarity index 93%
rename from src/darwin.cc
rename to src/darwin.mm
index cfb95c50a..a41a03b4a 100644
--- a/src/darwin.cc
+++ b/src/darwin.mm
@@ -42,12 +42,6 @@
*is available. patched the _csr_check function to return the bool bit instead.
*/
-/*
- * Apologies for the code style...
- * In my eyes it feels better to have
- * different styles at some specific places... :)
- */
-
#include "conky.h" // for struct info
#include "darwin.h"
@@ -74,6 +68,16 @@
#include "darwin_sip.h" // sip status
+#include
+
+#ifdef BUILD_IPGFREQ
+#include
+#endif
+
+#ifdef BUILD_WLAN
+#import
+#endif
+
/* clock_gettime includes */
#ifndef HAVE_CLOCK_GETTIME
#include
@@ -106,6 +110,10 @@ void eprintf(const char *fmt, ...) {
*/
static conky::simple_config_setting top_cpu_separate("top_cpu_separate",
false, true);
+/*
+ * used by update_cpu_usage()
+ */
+struct cpusample *sample_handle = nullptr;
static int getsysctl(const char *name, void *ptr, size_t len) {
size_t nlen = len;
@@ -219,13 +227,12 @@ typedef struct memorysample {
* Gets systemTime, userTime and idleTime for CPU
* MenuMeters has been great inspiration for this function
*/
-static void get_cpu_sample(struct cpusample *sample) {
+static void get_cpu_sample(struct cpusample **sample) {
host_name_port_t machHost;
natural_t processorCount;
processor_cpu_load_info_t processorTickInfo;
mach_msg_type_number_t processorInfoCount;
- struct cpusample *samples = nullptr;
-
+
machHost = mach_host_self();
kern_return_t err = host_processor_info(
@@ -237,22 +244,15 @@ static void get_cpu_sample(struct cpusample *sample) {
return;
}
- /*
- * allocate ncpus+1 cpusample structs (one foreach CPU)
- * ** samples[0] is overal CPU usage
- */
- samples = new struct cpusample[processorCount + 1];
- memset(samples, 0, sizeof(cpusample) * (processorCount + 1));
-
/*
* start from samples[1] because samples[0] is overall CPU usage
*/
for (natural_t i = 1; i < processorCount + 1; i++) {
- samples[i].totalSystemTime =
+ (*sample)[i].totalSystemTime =
processorTickInfo[i - 1].cpu_ticks[CPU_STATE_SYSTEM],
- samples[i].totalUserTime =
+ (*sample)[i].totalUserTime =
processorTickInfo[i - 1].cpu_ticks[CPU_STATE_USER],
- samples[i].totalIdleTime =
+ (*sample)[i].totalIdleTime =
processorTickInfo[i - 1].cpu_ticks[CPU_STATE_IDLE];
}
@@ -260,24 +260,37 @@ static void get_cpu_sample(struct cpusample *sample) {
* sum up all totals
*/
for (natural_t i = 1; i < processorCount + 1; i++) {
- samples[0].totalSystemTime += samples[i].totalSystemTime;
- samples[0].totalUserTime += samples[i].totalUserTime;
- samples[0].totalIdleTime += samples[i].totalIdleTime;
+ (*sample)[0].totalSystemTime += (*sample)[i].totalSystemTime;
+ (*sample)[0].totalUserTime += (*sample)[i].totalUserTime;
+ (*sample)[0].totalIdleTime += (*sample)[i].totalIdleTime;
}
- /*
- * set the sample pointer
- */
- sample->totalSystemTime = samples[0].totalSystemTime;
- sample->totalUserTime = samples[0].totalUserTime;
- sample->totalIdleTime = samples[0].totalIdleTime;
-
/*
* Dealloc
*/
vm_deallocate(mach_task_self(), (vm_address_t)processorTickInfo,
static_cast(processorInfoCount * sizeof(natural_t)));
- delete[] samples;
+}
+
+void allocate_cpu_sample(struct cpusample **sample) {
+ if (*sample != nullptr)
+ return;
+
+ /*
+ * allocate ncpus+1 cpusample structs (one foreach CPU)
+ * ** sample_handle[0] is overal CPU usage
+ */
+ *sample = reinterpret_cast(malloc(sizeof(cpusample) * (info.cpu_count + 1)));
+ memset(*sample, 0, sizeof(cpusample) * (info.cpu_count + 1));
+
+ sample_handle = *sample; /* use a public handle for deallocating */
+}
+
+void free_cpu(struct text_object *) {
+ if (sample_handle != nullptr) {
+ free(sample_handle);
+ sample_handle = nullptr;
+ }
}
/*
@@ -567,11 +580,9 @@ uint64_t get_physical_memory() {
}
int update_meminfo() {
- /* XXX implement remaining memory-related variables (see conky.h) */
- /* XXX conky breaks the values ... :( probably some rounding problem...
- Though we get the right values (based on top) */
- /* XXX probably investigate the "probably apple keeps some info secret" */
-
+
+ /* XXX See #34 */
+
vm_size_t page_size = getpagesize(); // get pagesize in bytes
unsigned long swap_avail, swap_free;
@@ -638,6 +649,14 @@ int update_meminfo() {
return 0;
}
+#ifdef BUILD_WLAN
+
+void update_wlan_stats(struct net_stat *ns) {
+
+}
+
+#endif
+
int update_net_stats() {
struct net_stat *ns;
double delta;
@@ -657,6 +676,10 @@ int update_net_stats() {
if ((ifa->ifa_flags & IFF_UP) != 0u) {
struct ifaddrs *iftmp;
+#ifdef BUILD_WLAN
+ update_wlan_stats(ns);
+#endif
+
ns->up = 1;
last_recv = ns->recv;
last_trans = ns->trans;
@@ -843,8 +866,6 @@ void get_cpu_count() {
info.cpu_count = 0;
}
- /* XXX this can be moved to update_cpu_usage() but keep here to follow linux
- * implementation */
if (info.cpu_usage == nullptr) {
/*
* Allocate ncpus+1 slots because cpu_usage[0] is overall usage.
@@ -864,16 +885,14 @@ struct cpu_info {
};
int update_cpu_usage() {
- /* XXX add support for multiple cpus (see linux.cc) */
-
static bool cpu_setup = 0;
long used, total;
static struct cpu_info *cpu = nullptr;
unsigned int malloc_cpu_size = 0;
extern void *global_cpu;
-
- struct cpusample sample {};
+
+ static struct cpusample *sample = nullptr;
static pthread_mutex_t last_stat_update_mutex = PTHREAD_MUTEX_INITIALIZER;
static double last_stat_update = 0.0;
@@ -905,19 +924,29 @@ int update_cpu_usage() {
global_cpu = cpu;
}
+ allocate_cpu_sample(&sample);
+
get_cpu_sample(&sample);
- total = sample.totalUserTime + sample.totalIdleTime + sample.totalSystemTime;
- used = total - sample.totalIdleTime;
- if ((total - cpu[0].oldtotal) != 0) {
- info.cpu_usage[0] = (static_cast(used - cpu[0].oldused)) /
- static_cast(total - cpu[0].oldtotal);
- } else {
- info.cpu_usage[0] = 0;
- }
+ /*
+ * Setup conky's structs for-each core
+ */
+ for (int i = 1; i < info.cpu_count + 1; i++) {
+ int j = i - 1;
+
+ total = sample[i].totalUserTime + sample[i].totalIdleTime + sample[i].totalSystemTime;
+ used = total - sample[i].totalIdleTime;
+
+ if ((total - cpu[j].oldtotal) != 0) {
+ info.cpu_usage[j] = (static_cast(used - cpu[j].oldused)) /
+ static_cast(total - cpu[j].oldtotal);
+ } else {
+ info.cpu_usage[j] = 0;
+ }
- cpu[0].oldused = used;
- cpu[0].oldtotal = total;
+ cpu[j].oldused = used;
+ cpu[j].oldtotal = total;
+ }
return 0;
}
@@ -974,50 +1003,62 @@ void get_acpi_fan(char * /*p_client_buffer*/, size_t /*client_buffer_size*/) {
/* void */
char get_freq(char *p_client_buffer, size_t client_buffer_size,
- const char *p_format, int divisor, unsigned int /*cpu*/) {
+ const char *p_format, int divisor, unsigned int cpu) {
+
+ if ((p_client_buffer == nullptr) || client_buffer_size <= 0 ||
+ (p_format == nullptr) || divisor <= 0) {
+ return 0;
+ }
+
+#ifdef BUILD_IPGFREQ
+ /*
+ * Our data is always the same for every core, so ignore |cpu| argument.
+ */
+
+ static bool initialised = false;
+
+ if (!initialised) {
+ IntelEnergyLibInitialize();
+ initialised = true;
+ }
+
+ int freq = 0;
+ GetIAFrequency(cpu, &freq);
+
+ snprintf(p_client_buffer, client_buffer_size, p_format,
+ static_cast(freq) / divisor);
+#else
/*
- * For now, we get the factory cpu frequency, not **current** cpu frequency
+ * We get the factory cpu frequency, not **current** cpu frequency
* (Also, it is always the same for every core, so ignore |cpu| argument)
+ * Enable BUILD_IPGFREQ for getting current frequency.
*/
-
- // XXX Probably find a way to get **current** cpu frequency
-
+
int mib[2];
unsigned int freq;
size_t len;
-
- if ((p_client_buffer == nullptr) || client_buffer_size <= 0 ||
- (p_format == nullptr) || divisor <= 0) {
- return 0;
- }
-
+
mib[0] = CTL_HW;
mib[1] = HW_CPU_FREQ;
len = sizeof(freq);
-
+
if (sysctl(mib, 2, &freq, &len, nullptr, 0) == 0) {
/*
* convert to MHz
*/
divisor *= 1000000;
-
+
snprintf(p_client_buffer, client_buffer_size, p_format,
static_cast(freq) / divisor);
} else {
snprintf(p_client_buffer, client_buffer_size, p_format, 0.0f);
return 0;
}
-
+#endif
+
return 1;
}
-#if 0
-void update_wifi_stats(void)
-{
- printf("update_wifi_stats: STUB but also in #if 0\n");
-}
-#endif
-
int update_diskio() {
printf("update_diskio: STUB\n");
return 0;
@@ -1058,11 +1099,13 @@ static void calc_cpu_usage_for_proc(struct process *proc, uint64_t total) {
*/
static void calc_cpu_total(struct process *proc, uint64_t *total) {
uint64_t current_total = 0; /* of current iteration */
- struct cpusample sample {};
-
+ struct cpusample *sample = nullptr;
+
+ allocate_cpu_sample(&sample);
+
get_cpu_sample(&sample);
current_total =
- sample.totalUserTime + sample.totalIdleTime + sample.totalSystemTime;
+ sample[0].totalUserTime + sample[0].totalIdleTime + sample[0].totalSystemTime;
*total = current_total - proc->previous_total_cpu_time;
proc->previous_total_cpu_time = current_total;
@@ -1175,17 +1218,7 @@ void get_top_info() {
struct kinfo_proc *p = nullptr;
/*
- * QUICKFIX for #16
- * XXX if we run conky -t '${top_mem mem 1}' it will crash because
- * info.cpu_count is not initialised.
- *
- * We can initialise it down here, but it seems like in the linux
- * implementation of get_top_info() there is no call to the get_cpu_count()
- * function. Neither is there in core.cc... If this is the case, when is
- * info.cpu_count initialised???
- *
- * Find a proper better place for get_cpu_count() call. (for comformance with
- * linux.cc)
+ * See #16
*/
get_cpu_count();
diff --git a/src/dragonfly.cc b/src/dragonfly.cc
index 689ceb34e..06fc207df 100644
--- a/src/dragonfly.cc
+++ b/src/dragonfly.cc
@@ -126,9 +126,7 @@ int check_mount(char *s) {
mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
for (i = mntsize - 1; i >= 0; i--) {
- if (strcmp(mntbuf[i].f_mntonname, s) == 0) {
- return 1;
- }
+ if (strcmp(mntbuf[i].f_mntonname, s) == 0) { return 1; }
}
return 0;
@@ -178,13 +176,9 @@ int update_net_stats(void) {
/* get delta */
delta = current_update_time - last_update_time;
- if (delta <= 0.0001) {
- return 0;
- }
+ if (delta <= 0.0001) { return 0; }
- if (getifaddrs(&ifap) < 0) {
- return 0;
- }
+ if (getifaddrs(&ifap) < 0) { return 0; }
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
ns = get_net_stat((const char *)ifa->ifa_name, nullptr, NULL);
@@ -196,9 +190,7 @@ int update_net_stats(void) {
last_recv = ns->recv;
last_trans = ns->trans;
- if (ifa->ifa_addr->sa_family != AF_LINK) {
- continue;
- }
+ if (ifa->ifa_addr->sa_family != AF_LINK) { continue; }
for (iftmp = ifa->ifa_next;
iftmp != nullptr && strcmp(ifa->ifa_name, iftmp->ifa_name) == 0;
@@ -286,9 +278,7 @@ void get_cpu_count(void) {
}
info.cpu_usage = (float *)malloc((info.cpu_count + 1) * sizeof(float));
- if (info.cpu_usage == nullptr) {
- CRIT_ERR(nullptr, NULL, "malloc");
- }
+ if (info.cpu_usage == nullptr) { CRIT_ERR(nullptr, NULL, "malloc"); }
}
struct cpu_info {
@@ -357,6 +347,8 @@ int update_cpu_usage(void) {
return 0;
}
+void free_cpu(struct text_object *) { /* no-op */ }
+
int update_load_average(void) {
double v[3];
@@ -489,9 +481,7 @@ void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size,
(void)adapter; // only linux uses this
- if (!p_client_buffer || client_buffer_size <= 0) {
- return;
- }
+ if (!p_client_buffer || client_buffer_size <= 0) { return; }
if (GETSYSCTL("hw.acpi.acline", state)) {
fprintf(stderr, "Cannot read sysctl \"hw.acpi.acline\"\n");
@@ -711,9 +701,7 @@ void get_top_info(void) {
#define APM_UNKNOWN 255
int apm_getinfo(int fd, apm_info_t aip) {
- if (ioctl(fd, APMIO_GETINFO, aip) == -1) {
- return -1;
- }
+ if (ioctl(fd, APMIO_GETINFO, aip) == -1) { return -1; }
return 0;
}
diff --git a/src/freebsd.cc b/src/freebsd.cc
index 8e27bad3b..76490414b 100644
--- a/src/freebsd.cc
+++ b/src/freebsd.cc
@@ -371,6 +371,8 @@ int update_cpu_usage(void) {
return 0;
}
+void free_cpu(struct text_object *) { /* no-op */ }
+
int update_load_average(void) {
double v[3];
@@ -641,9 +643,7 @@ int update_diskio(void) {
free(dev_select);
}
- if (statinfo_cur.dinfo->mem_ptr) {
- free(statinfo_cur.dinfo->mem_ptr);
- }
+ if (statinfo_cur.dinfo->mem_ptr) { free(statinfo_cur.dinfo->mem_ptr); }
free(statinfo_cur.dinfo);
return 0;
}
diff --git a/src/haiku.cc b/src/haiku.cc
index 2f4a217fa..6138374ab 100644
--- a/src/haiku.cc
+++ b/src/haiku.cc
@@ -143,6 +143,8 @@ int update_cpu_usage() {
return 1;
}
+void free_cpu(struct text_object *) { /* no-op */ }
+
int update_load_average() {
// TODO
return 1;
diff --git a/src/linux.cc b/src/linux.cc
index ec425c9d7..b10fd7ed1 100644
--- a/src/linux.cc
+++ b/src/linux.cc
@@ -936,6 +936,8 @@ int update_cpu_usage(void) {
return 0;
}
+void free_cpu(struct text_object *) { /* no-op */ }
+
// fscanf() that reads floats with points even if you are using a locale where
// floats are with commas
int fscanf_no_i18n(FILE *stream, const char *format, ...) {
diff --git a/src/net_stat.cc b/src/net_stat.cc
index 710ca7a88..4505bd704 100644
--- a/src/net_stat.cc
+++ b/src/net_stat.cc
@@ -476,7 +476,11 @@ int interface_up(struct text_object *obj) {
if (dev == nullptr) { return 0; }
+#if defined(__APPLE__) && defined(__MACH__)
+ if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
+#else
if ((fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0)) < 0) {
+#endif
CRIT_ERR(nullptr, nullptr, "could not create sockfd");
return 0;
}
diff --git a/src/netbsd.cc b/src/netbsd.cc
index e844b20f0..4d59c9d43 100644
--- a/src/netbsd.cc
+++ b/src/netbsd.cc
@@ -286,6 +286,8 @@ void update_cpu_usage() {
oldtotal = total;
}
+void free_cpu(struct text_object *) { /* no-op */ }
+
void update_load_average() {
double v[3];
diff --git a/src/openbsd.cc b/src/openbsd.cc
index 758572aa9..870be3623 100644
--- a/src/openbsd.cc
+++ b/src/openbsd.cc
@@ -400,6 +400,9 @@ void update_cpu_usage() {
#endif
}
+void free_cpu(struct text_object *) { /* no-op */
+}
+
void update_load_average() {
double v[3];
diff --git a/src/solaris.cc b/src/solaris.cc
index c28d94088..eee15160e 100644
--- a/src/solaris.cc
+++ b/src/solaris.cc
@@ -314,6 +314,8 @@ int update_cpu_usage(void) {
return 0;
}
+void free_cpu(struct text_object *) { /* no-op */ }
+
void update_proc_entry(struct process *p) {
psinfo_t proc;
int fd;