summaryrefslogtreecommitdiff
path: root/wmiistatus.c
diff options
context:
space:
mode:
authorMichael Stapelberg <michael+git@stapelberg.de>2009-01-25 22:51:54 +0100
committerMichael Stapelberg <michael+git@stapelberg.de>2009-01-25 22:51:54 +0100
commit62fe9d12105d2aeab21762850a8140793087b9aa (patch)
tree466e4f766681bc0c976903832eec758ad9234000 /wmiistatus.c
parent851dad965552580e3649d148a6f2fadeec04c6f7 (diff)
Add code for getting process status (running/not) and load on NetBSD
Diffstat (limited to 'wmiistatus.c')
-rw-r--r--wmiistatus.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/wmiistatus.c b/wmiistatus.c
index f4dfb16..5c66302 100644
--- a/wmiistatus.c
+++ b/wmiistatus.c
@@ -51,9 +51,15 @@
#include <glob.h>
#include <dirent.h>
#include <getopt.h>
+
#ifdef LINUX
#include <linux/ethtool.h>
#include <linux/sockios.h>
+#else
+/* TODO: correctly check for *BSD */
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/resource.h>
#endif
#define _IS_WMIISTATUS_C
@@ -404,8 +410,18 @@ static bool process_runs(const char *path) {
(void)read(fd, pidbuf, sizeof(pidbuf));
(void)close(fd);
+#ifdef LINUX
(void)snprintf(procbuf, sizeof(procbuf), "/proc/%ld", strtol(pidbuf, NULL, 10));
return (stat(procbuf, &statbuf) >= 0);
+#else
+ /* TODO: correctly check for NetBSD. Evaluate if this runs on OpenBSD/FreeBSD */
+ struct kinfo_proc info;
+ size_t length = sizeof(struct kinfo_proc);
+ int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, strtol(pidbuf, NULL, 10) };
+ if (sysctl(mib, 4, &info, &length, NULL, 0) < 0)
+ return false;
+ return (length != 0);
+#endif
}
int main(int argc, char *argv[]) {
@@ -462,11 +478,25 @@ int main(int argc, char *argv[]) {
write_to_statusbar(concat(order[ORDER_BATTERY], "battery"), get_battery_info());
/* Get load */
+#ifdef LINUX
if ((load_avg = open("/proc/loadavg", O_RDONLY)) == -1)
die("Could not open /proc/loadavg\n");
(void)read(load_avg, part, sizeof(part));
(void)close(load_avg);
*skip_character(part, ' ', 3) = '\0';
+#else
+ /* TODO: correctly check for NetBSD, check if it works the same on *BSD */
+ struct loadavg load;
+ size_t length = sizeof(struct loadavg);
+ int mib[2] = { CTL_VM, VM_LOADAVG };
+ if (sysctl(mib, 2, &load, &length, NULL, 0) < 0)
+ die("Could not sysctl({ CTL_VM, VM_LOADAVG })\n");
+ double scale = load.fscale;
+ (void)snprintf(part, sizeof(part), "%.02f %.02f %.02f",
+ (double)load.ldavg[0] / scale,
+ (double)load.ldavg[1] / scale,
+ (double)load.ldavg[2] / scale);
+#endif
write_to_statusbar(concat(order[ORDER_LOAD], "load"), part);
if (time_format) {