status

statusbar program for dwm
git clone anongit@rnpnr.xyz:status.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 83d1fc8f7c958e1375f57235a5ffcf4b1d800a4e
Parent: 0277eba1d73570d8bbb38deb8494a866762a055a
Author: opask
Date:   Fri,  9 Nov 2018 08:52:56 -0700

handle our own signals

Diffstat:
Mconfig.mk | 3++-
Mstatus.c | 19++++++++++++++++++-
2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/config.mk b/config.mk @@ -2,5 +2,6 @@ PREFIX = / LIBS = -lmpdclient -lX11 -CFLAGS = -O2 -std=c99 -Wall -pedantic +CPPFLAGS = -D_POSIX_C_SOURCE +CFLAGS = -O2 -std=c99 -Wall -pedantic $(CPPFLAGS) LDFLAGS = $(LIBS) diff --git a/status.c b/status.c @@ -1,11 +1,14 @@ +#include <signal.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <time.h> #include <unistd.h> #include <mpd/client.h> #include <X11/Xlib.h> +static int done = 0; static char buf[1024]; static Display *dpy; @@ -21,6 +24,14 @@ die(const char *errstr, ...) exit(1); } +static void +terminate(const int signo) +{ + (void)signo; + + done = 1; +} + static char * smprintf(const char *fmt, ...) { @@ -95,15 +106,21 @@ mpd(enum mpd_tag_type type) int main(void) { + struct sigaction sa; char *status; char *time; char *song; char *artist; + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = terminate; + sigaction(SIGINT, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); + if (!(dpy = XOpenDisplay(NULL))) die("XOpenDisplay: can't open display\n"); - for (;; sleep(1)) { + for (; !done; sleep(1)) { time = gettime("%Y年%m月%d日 ♦ %R"); song = mpd(MPD_TAG_TITLE); artist = mpd(MPD_TAG_ARTIST);