};
char buf[1024];
-static int done;
+static volatile sig_atomic_t done;
static Display *dpy;
#include "config.h"
static void
terminate(const int signo)
{
- (void)signo;
-
- done = 1;
+ if (signo != SIGUSR1)
+ done = 1;
}
static void
static void
usage(void)
{
- die("usage: %s [-s]", argv0);
+ die("usage: %s [-s] [-1]", argv0);
}
int
sflag = 0;
ARGBEGIN {
+ case '1':
+ done = 1;
+ /* fallthrough */
case 's':
sflag = 1;
break;
act.sa_handler = terminate;
sigaction(SIGINT, &act, NULL);
sigaction(SIGTERM, &act, NULL);
-
- if (sflag) {
- setbuf(stdout, NULL);
- }
+ act.sa_flags |= SA_RESTART;
+ sigaction(SIGUSR1, &act, NULL);
if (!sflag && !(dpy = XOpenDisplay(NULL))) {
die("XOpenDisplay: Failed to open display");
}
- while (!done) {
+ do {
if (clock_gettime(CLOCK_MONOTONIC, &start) < 0) {
die("clock_gettime:");
}
}
if (sflag) {
- if (printf("%s\n", status) < 0) {
- die("printf:");
- }
+ puts(status);
+ fflush(stdout);
+ if (ferror(stdout))
+ die("puts:");
} else {
- if (XStoreName(dpy, DefaultRootWindow(dpy), status) < 0) {
+ if (XStoreName(dpy, DefaultRootWindow(dpy), status)
+ < 0) {
die("XStoreName: Allocation failed");
}
XFlush(dpy);
}
}
}
- }
+ } while (!done);
if (!sflag) {
XStoreName(dpy, DefaultRootWindow(dpy), NULL);