[wiki] [sites] [slstatus][patch][signals] bug fixes || sewn

From: <git_AT_suckless.org>
Date: Thu, 02 May 2024 14:57:04 +0200

commit 384985feecf71e13214fd6ceda12b9171f439453
Author: sewn <sewn_AT_disroot.org>
Date: Thu May 2 15:56:28 2024 +0300

    [slstatus][patch][signals] bug fixes

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
index 12bfb071..dd9f60aa 100644
--- a/tools.suckless.org/slstatus/patches/signals/slstatus-signals-1.0.patch
+++ b/tools.suckless.org/slstatus/patches/signals/slstatus-signals-1.0.patch
_AT_@ -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_AT_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
 _AT_@ -6,8 +6,8 @@ const unsigned int interval = 1000;
_AT_@ -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
 _AT_@ -15,20 +15,19 @@ struct arg {
_AT_@ -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];
_AT_@ -65,22 +65,21 @@ index fd31313..ae12e7d 100644
  
  static void
  difftimespec(struct timespec *res, struct timespec *a, struct timespec *b)
-_AT_@ -44,17 +43,69 @@ usage(void)
+_AT_@ -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;
_AT_@ -92,14 +91,14 @@ index fd31313..ae12e7d 100644
 + break;
 + }
 +
++ if (!update)
++ return;
++
 + status[0] = ' + for (i = 0; i < LEN(args); i++)
 + strcat(status, statuses[i]);
 + status[strlen(status)] = ' +
-+ if (!update)
-+ return;
-+
 + if (sflag) {
 + puts(status);
 + fflush(stdout);
_AT_@ -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;
 +}
_AT_@ -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);
-_AT_@ -72,11 +123,13 @@ main(int argc, char *argv[])
+_AT_@ -72,41 +121,23 @@ main(int argc, char *argv[])
                  usage();
  
          memset(&act, 0, sizeof(act));
_AT_@ -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");
-_AT_@ -85,28 +138,7 @@ main(int argc, char *argv[])
+
++ printstatus(-1, -1);
++
+ do {
                  if (clock_gettime(CLOCK_MONOTONIC, &start) < 0)
                          die("clock_gettime:");
  
_AT_@ -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)
-_AT_@ -117,10 +149,11 @@ main(int argc, char *argv[])
+_AT_@ -117,10 +148,11 @@ main(int argc, char *argv[])
                          intspec.tv_nsec = (interval % 1000) * 1E6;
                          difftimespec(&wait, &intspec, &diff);
  
_AT_@ -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);
Received on Thu May 02 2024 - 14:57:04 CEST

This archive was generated by hypermail 2.3.0 : Thu May 02 2024 - 15:00:51 CEST