summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile10
-rw-r--r--config.h2
-rw-r--r--wmiistatus.c23
-rw-r--r--wmiistatus.h4
-rwxr-xr-xwmiistatus.init35
5 files changed, 62 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index 2af2010..09f537f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,2 +1,10 @@
-all:
+wmiistatus: wmiistatus.c wmiistatus.h config.h Makefile
gcc -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare -g -O2 -o wmiistatus wmiistatus.c
+
+install:
+ install -m 755 -d $(DESTDIR)/usr/bin
+ install -m 755 -d $(DESTDIR)/etc/init.d
+ install -m 755 wmiistatus $(DESTDIR)/usr/bin/wmiistatus
+ install -m 755 wmiistatus.init $(DESTDIR)/etc/init.d/wmiistatus
+
+all: wmiistatus
diff --git a/config.h b/config.h
index 3f55af8..c142add 100644
--- a/config.h
+++ b/config.h
@@ -1,5 +1,7 @@
const char *wlan_interface = "wlan0";
const char *eth_interface = "eth0";
const char *wmii_path = "/mnt/wmii/rbar/status";
+const char *time_format = "%d.%m.%Y %H:%M:%S";
+const char *battery = "/sys/class/power_supply/BAT0/uevent";
const char *run_watches[] = {"DHCP", "/var/run/dhclient*.pid",
"VPN", "/var/run/vpnc*.pid"};
diff --git a/wmiistatus.c b/wmiistatus.c
index f516849..00aa487 100644
--- a/wmiistatus.c
+++ b/wmiistatus.c
@@ -38,6 +38,7 @@
#include <stdio.h>
#include <time.h>
#include <stdbool.h>
+#include <stdarg.h>
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
@@ -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/<pid> 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(&current_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);
}
diff --git a/wmiistatus.h b/wmiistatus.h
index 13ec2c7..1e7f59f 100644
--- a/wmiistatus.h
+++ b/wmiistatus.h
@@ -6,11 +6,11 @@ static bool first_push = true;
typedef enum { CS_DISCHARGING, CS_CHARGING, CS_FULL } charging_status_t;
static void write_to_statusbar(const char *message);
-static void die(const char *message);
+static void die(const char *fmt, ...);
static char *skip_character(char *input, char character, int amount);
static void push_part(const char *input, const int n);
static char *get_battery_info(void);
static char *get_wireless_info(void);
static char *get_ip_address(const char *interface);
static char *get_eth_info(void);
-bool process_runs(const char *path);
+static bool process_runs(const char *path);
diff --git a/wmiistatus.init b/wmiistatus.init
new file mode 100755
index 0000000..576340f
--- /dev/null
+++ b/wmiistatus.init
@@ -0,0 +1,35 @@
+#!/bin/sh
+#
+### BEGIN INIT INFO
+# Provides: wmiistatus
+# Required-Start:
+# Required-Stop:
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: little application to fill up wmii's status bar
+# Description: little application to fill up wmii's status bar
+### END INIT INFO
+
+# For the pidfile, you must be root. wmiistatus itself runs as user just fine
+[ $UID -eq 0 ] || { echo "You need to be root"; exit 1; }
+
+. /lib/lsb/init-functions
+
+case "$1" in
+start) log_daemon_msg "Starting wmii status bar filler" "wmiistatus"
+ start-stop-daemon --start --background --quiet --make-pidfile --pidfile /var/run/wmiistatus.pid --name wmiistatus --startas /usr/bin/wmiistatus
+ log_end_msg $?
+ ;;
+stop) log_daemon_msg "Stopping wmii status bar filler" "wmiistatus"
+ start-stop-daemon --stop --quiet --pidfile /var/run/wmiistatus.pid --name wmiistatus
+ log_end_msg $?
+ ;;
+restart|reload|force-reload) log_daemon_msg "Restarting wmii status bar filler" "wmiistatus"
+ start-stop-daemon --stop --retry 5 --quiet --pidfile /var/run/wmiistatus.pid --name wmiistatus
+ start-stop-daemon --start --background --quiet --make-pidfile --pidfile /var/run/wmiistatus.pid --name wmiistatus --startas /usr/bin/wmiistatus
+ ;;
+*) log_action_msg "Usage: $0 {start|stop|restart|reload|force-reload}"
+ exit 2
+ ;;
+esac
+exit 0