X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/682c0fedde04fe6713539726494ec2db67ba5d2a..d1b23e5509863fd0790261b2b388e687d5218d53:/slstatus.c?ds=sidebyside diff --git a/slstatus.c b/slstatus.c index 7776fd5..0806773 100644 --- a/slstatus.c +++ b/slstatus.c @@ -18,7 +18,7 @@ struct arg { }; char buf[1024]; -static int done; +static volatile sig_atomic_t done; static Display *dpy; #include "config.h" @@ -26,9 +26,8 @@ static Display *dpy; static void terminate(const int signo) { - (void)signo; - - done = 1; + if (signo != SIGUSR1) + done = 1; } static void @@ -72,10 +71,8 @@ main(int argc, char *argv[]) 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"); @@ -99,11 +96,13 @@ main(int argc, char *argv[]) } 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);