Re: [hackers] [slstatus][PATCH] Handle SIGUSR1 for forced refreshes

From: Mart Lubbers <mart_AT_martlubbers.net>
Date: Thu, 16 Jul 2020 14:21:21 +0200

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 | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/slstatus.c b/slstatus.c
index 96fa5b6..ee42786 100644
--- a/slstatus.c
+++ b/slstatus.c
_AT_@ -18,7 +18,7 @@ struct arg {
 };
 char buf[1024];
-static int done;
+static volatile sig_atomic_t done;
 static Display *dpy;
 #include "config.h"
_AT_@ -26,9 +26,9 @@ static Display *dpy;
 static void
 terminate(const int signo)
 {
-       (void)signo;
-
-       done = 1;
+       if (signo != SIGUSR1) {
+               done = 1;
+       }
 }
 static void
_AT_@ -72,6 +72,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");
--
2.20.1

Received on Thu Jul 16 2020 - 14:21:21 CEST

This archive was generated by hypermail 2.3.0 : Thu Jul 16 2020 - 15:24:31 CEST