Handle SIGUSR1 for forced refreshes
authorMart Lubbers <mart@martlubbers.net>
Thu, 18 Jun 2020 06:46:12 +0000 (08:46 +0200)
committerAaron Marcher <me@drkhsh.at>
Mon, 30 Nov 2020 20:23:49 +0000 (21:23 +0100)
At some point one might want to force a refresh for example after
checking email or changing the volume. Sending a SIGUSR1 achieves this
now

slstatus.c

index 96fa5b603ba431f64de2b67073eb211269aac897..0806773a7d1173cfa8bfbc0983d8e5a28743b399 100644 (file)
@@ -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,6 +71,8 @@ main(int argc, char *argv[])
        act.sa_handler = terminate;
        sigaction(SIGINT,  &act, NULL);
        sigaction(SIGTERM, &act, NULL);
+       act.sa_flags |= SA_RESTART;
+       sigaction(SIGUSR1, &act, NULL);
 
        if (!sflag && !(dpy = XOpenDisplay(NULL))) {
                die("XOpenDisplay: Failed to open display");