-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
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"};
#include <stdio.h>
#include <time.h>
#include <stdbool.h>
+#include <stdarg.h>
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
* 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);
}
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;
* 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;
/* 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);
}
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);
--- /dev/null
+#!/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