From e31a85eb3b9d331d73254ceb2d6156cc8e66c40a Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 4 Oct 2008 19:32:35 +0200 Subject: Make some formats/paths configurable, add initscript --- wmiistatus.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'wmiistatus.c') diff --git a/wmiistatus.c b/wmiistatus.c index f516849..00aa487 100644 --- a/wmiistatus.c +++ b/wmiistatus.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -63,8 +64,14 @@ static void write_to_statusbar(const char *message) { * Write errormessage to statusbar and exit * */ -static void die(const char *message) { - write_to_statusbar(message); +static void die(const char *fmt, ...) { + char buffer[512]; + va_list ap; + va_start(ap, fmt); + vsprintf(buffer, fmt, ap); + va_end(ap); + + write_to_statusbar(buffer); exit(-1); } @@ -97,9 +104,9 @@ static char *get_battery_info() { char buf[1024]; static char part[512]; char *walk, *last = buf; - int fd = open("/sys/class/power_supply/BAT0/uevent", O_RDONLY); + int fd = open(battery, O_RDONLY); if (fd == -1) - die("Could not open /sys/class/power_supply/BAT0/uevent"); + die("Could not open %s", battery); int full_design = -1, remaining = -1, present_rate = -1; @@ -237,7 +244,7 @@ static char *get_eth_info() { * Checks if the PID in path is still valid by checking if /proc/ exists * */ -bool process_runs(const char *path) { +static bool process_runs(const char *path) { char pidbuf[512], procbuf[512]; static glob_t globbuf; @@ -291,12 +298,10 @@ int main(void) { /* Get date & time */ time_t current_time = time(NULL); struct tm *current_tm = localtime(¤t_time); - strftime(part, sizeof(part), "%d.%m.%Y %H:%M:%S", current_tm); + strftime(part, sizeof(part), time_format, current_tm); push_part(part, strlen(part)); - int fd = open("/mnt/wmii/rbar/status", O_RDWR); - write(fd, output, strlen(output)); - close(fd); + write_to_statusbar(output); sleep(1); } -- cgit v1.2.3