sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit 384985feecf71e13214fd6ceda12b9171f439453
parent ac49fc10ff3095febc4a609e98a56ff246c834c9
Author: sewn <sewn@disroot.org>
Date:   Thu,  2 May 2024 15:56:28 +0300

[slstatus][patch][signals] bug fixes

Diffstat:
Mtools.suckless.org/slstatus/patches/signals/slstatus-signals-1.0.patch | 62+++++++++++++++++++++++++++++++-------------------------------
1 file changed, 31 insertions(+), 31 deletions(-)

diff --git a/tools.suckless.org/slstatus/patches/signals/slstatus-signals-1.0.patch b/tools.suckless.org/slstatus/patches/signals/slstatus-signals-1.0.patch @@ -1,15 +1,15 @@ -From 048bac828383fd30232e4b8aeb764e0de7754f7f Mon Sep 17 00:00:00 2001 +From 08c9d252bb855b5a77b9bbcd29b31b71219d0e72 Mon Sep 17 00:00:00 2001 From: sewn <sewn@disroot.org> -Date: Thu, 2 May 2024 11:59:01 +0300 +Date: Thu, 2 May 2024 15:53:30 +0300 Subject: [PATCH] implement signals & intervals --- - config.def.h | 11 +++-- - slstatus.c | 111 +++++++++++++++++++++++++++++++++------------------ - 2 files changed, 79 insertions(+), 43 deletions(-) + config.def.h | 11 ++++-- + slstatus.c | 110 +++++++++++++++++++++++++++++++++------------------ + 2 files changed, 78 insertions(+), 43 deletions(-) diff --git a/config.def.h b/config.def.h -index d805331..a36cdb7 100644 +index d805331..7fbd164 100644 --- a/config.def.h +++ b/config.def.h @@ -6,8 +6,8 @@ const unsigned int interval = 1000; @@ -30,13 +30,13 @@ index d805331..a36cdb7 100644 - /* function format argument */ - { datetime, "%s", "%F %T" }, + /* function format argument interval signal */ -+ { datetime, "%s", "%F %T", 1, 0 }, ++ { datetime, "%s", "%F %T", 1, -1 }, }; + +/* maximum output string length */ +#define MAXLEN CMDLEN * LEN(args) diff --git a/slstatus.c b/slstatus.c -index fd31313..ae12e7d 100644 +index fd31313..2c953cc 100644 --- a/slstatus.c +++ b/slstatus.c @@ -15,20 +15,19 @@ struct arg { @@ -44,7 +44,7 @@ index fd31313..ae12e7d 100644 const char *fmt; const char *args; + unsigned int interval; -+ unsigned int signal; ++ int signal; }; char buf[1024]; @@ -65,22 +65,21 @@ index fd31313..ae12e7d 100644 static void difftimespec(struct timespec *res, struct timespec *a, struct timespec *b) -@@ -44,17 +43,69 @@ usage(void) +@@ -44,17 +43,67 @@ usage(void) die("usage: %s [-v] [-s] [-1]", argv0); } +static void -+printstatus(int it, unsigned int upsig) ++printstatus(int it, int upsig) +{ + size_t i; -+ int update; ++ int update = 0; + char status[MAXLEN]; + const char *res; + + for (i = 0; i < LEN(args); i++) { -+ if ((upsig == 0 || upsig != args[i].signal) && -+ ((args[i].interval == 0 || it % args[i].interval != 0 || upsig != 0) && -+ it != -1)) ++ if (!(((args[i].interval > 0 && it > 0 && !(it % args[i].interval)) && upsig < 0) || ++ (upsig > -1 && args[i].signal == upsig) || (it == -1 && upsig == -1))) + continue; + + update = 1; @@ -92,14 +91,14 @@ index fd31313..ae12e7d 100644 + break; + } + ++ if (!update) ++ return; ++ + status[0] = '\0'; + for (i = 0; i < LEN(args); i++) + strcat(status, statuses[i]); + status[strlen(status)] = '\0'; + -+ if (!update) -+ return; -+ + if (sflag) { + puts(status); + fflush(stdout); @@ -117,9 +116,9 @@ index fd31313..ae12e7d 100644 +sighandler(const int signo) +{ + if (signo <= SIGRTMAX && signo >= SIGRTMIN) -+ printstatus(0, signo - SIGRTMIN); ++ printstatus(-1, signo - SIGRTMIN); + else if (signo == SIGUSR1) -+ printstatus(-1, 0); ++ printstatus(-1, -1); + else + done = 1; +} @@ -133,14 +132,13 @@ index fd31313..ae12e7d 100644 - int sflag, ret; - char status[MAXLEN]; - const char *res; -+ size_t i; -+ int ret, time = -1; ++ int i, ret, time = 0; - sflag = 0; ARGBEGIN { case 'v': die("slstatus-"VERSION); -@@ -72,11 +123,13 @@ main(int argc, char *argv[]) +@@ -72,41 +121,23 @@ main(int argc, char *argv[]) usage(); memset(&act, 0, sizeof(act)); @@ -150,13 +148,15 @@ index fd31313..ae12e7d 100644 sigaction(SIGTERM, &act, NULL); - act.sa_flags |= SA_RESTART; sigaction(SIGUSR1, &act, NULL); -+ for (i = 0; i < LEN(args); i++) -+ if (args[i].signal > 0) -+ sigaction(SIGRTMIN+args[i].signal, &act, NULL); ++ for (i = SIGRTMIN; i <= SIGRTMAX; i++) ++ sigaction(i, &act, NULL); if (!sflag && !(dpy = XOpenDisplay(NULL))) die("XOpenDisplay: Failed to open display"); -@@ -85,28 +138,7 @@ main(int argc, char *argv[]) + ++ printstatus(-1, -1); ++ + do { if (clock_gettime(CLOCK_MONOTONIC, &start) < 0) die("clock_gettime:"); @@ -182,11 +182,11 @@ index fd31313..ae12e7d 100644 - die("XStoreName: Allocation failed"); - XFlush(dpy); - } -+ printstatus(time++, 0); ++ printstatus(time++, -1); if (!done) { if (clock_gettime(CLOCK_MONOTONIC, &current) < 0) -@@ -117,10 +149,11 @@ main(int argc, char *argv[]) +@@ -117,10 +148,11 @@ main(int argc, char *argv[]) intspec.tv_nsec = (interval % 1000) * 1E6; difftimespec(&wait, &intspec, &diff); @@ -196,8 +196,8 @@ index fd31313..ae12e7d 100644 - die("nanosleep:"); + do + ret = nanosleep(&wait, &wait); -+ while (wait.tv_sec >= 0 && ret < 0 && errno == EINTR); -+ if (ret < 0) ++ while (wait.tv_sec >= 0 && ret < 0 && errno != EINTR && !done); ++ if (ret < 0 && errno != EINTR) + die("nanosleep:"); } } while (!done);