summaryrefslogtreecommitdiff
path: root/bspwm/0001-Revamp-signal-handling.patch
diff options
context:
space:
mode:
Diffstat (limited to 'bspwm/0001-Revamp-signal-handling.patch')
-rw-r--r--bspwm/0001-Revamp-signal-handling.patch106
1 files changed, 106 insertions, 0 deletions
diff --git a/bspwm/0001-Revamp-signal-handling.patch b/bspwm/0001-Revamp-signal-handling.patch
new file mode 100644
index 0000000..6399b39
--- /dev/null
+++ b/bspwm/0001-Revamp-signal-handling.patch
@@ -0,0 +1,106 @@
+From 7fbc56a7be07d25d38aab5c300bed433ec6b1f58 Mon Sep 17 00:00:00 2001
+From: James Cook <falsifian@falsifian.org>
+Date: Fri, 12 Jan 2024 01:02:53 +0000
+Subject: [PATCH 1/3] Revamp signal handling.
+
+- Change from signal to sigaction, which is more portable.
+
+- Install a handler for SIGPIPE instead of ignoring it, to avoid
+ passing on the ignored status to other programs launched from
+ bspwm.
+
+- Use SA_NOCLDWAIT to avoid the need to call waitpid. (NB if waitpid
+ were called in the handler, it would be a good idea to protect
+ errno.)
+
+- Declare the "running" global as volatile sig_atomic_t, as recommended
+ for values modified from signal handlers.
+---
+ src/bspwm.c | 29 +++++++++++++++++------------
+ src/bspwm.h | 2 +-
+ 2 files changed, 18 insertions(+), 13 deletions(-)
+
+diff --git a/src/bspwm.c b/src/bspwm.c
+index 4619a0c..f1d1e6c 100644
+--- a/src/bspwm.c
++++ b/src/bspwm.c
+@@ -27,7 +27,6 @@
+ #include <sys/stat.h>
+ #include <sys/types.h>
+ #include <sys/time.h>
+-#include <sys/wait.h>
+ #include <sys/socket.h>
+ #include <sys/un.h>
+ #include <fcntl.h>
+@@ -87,7 +86,7 @@ bool auto_raise;
+ bool sticky_still;
+ bool hide_sticky;
+ bool record_history;
+-bool running;
++volatile sig_atomic_t running;
+ bool restart;
+ bool randr;
+
+@@ -104,6 +103,7 @@ int main(int argc, char *argv[])
+ xcb_generic_event_t *event;
+ char *end;
+ int opt;
++ struct sigaction sigact;
+
+ while ((opt = getopt(argc, argv, "hvc:s:o:")) != -1) {
+ switch (opt) {
+@@ -194,11 +194,20 @@ int main(int argc, char *argv[])
+
+ fcntl(sock_fd, F_SETFD, FD_CLOEXEC | fcntl(sock_fd, F_GETFD));
+
+- signal(SIGINT, sig_handler);
+- signal(SIGHUP, sig_handler);
+- signal(SIGTERM, sig_handler);
+- signal(SIGCHLD, sig_handler);
+- signal(SIGPIPE, SIG_IGN);
++ sigact.sa_handler = sig_handler;
++ sigemptyset(&sigact.sa_mask);
++ sigact.sa_flags = SA_RESTART;
++ sigaction(SIGINT, &sigact, NULL);
++ sigaction(SIGHUP, &sigact, NULL);
++ sigaction(SIGTERM, &sigact, NULL);
++ /* We avoid using SIG_IGN with SIGPIPE because that would be preserved across
++ exec. */
++ sigaction(SIGPIPE, &sigact, NULL);
++
++ sigact.sa_handler = SIG_IGN;
++ sigact.sa_flags = SA_NOCLDWAIT;
++ sigaction(SIGCHLD, &sigact, NULL);
++
+ run_config(run_level);
+ running = true;
+
+@@ -527,11 +536,7 @@ bool check_connection (xcb_connection_t *dpy)
+
+ void sig_handler(int sig)
+ {
+- if (sig == SIGCHLD) {
+- signal(sig, sig_handler);
+- while (waitpid(-1, 0, WNOHANG) > 0)
+- ;
+- } else if (sig == SIGINT || sig == SIGHUP || sig == SIGTERM) {
++ if (sig == SIGINT || sig == SIGHUP || sig == SIGTERM) {
+ running = false;
+ }
+ }
+diff --git a/src/bspwm.h b/src/bspwm.h
+index 30f972e..9ee3e52 100644
+--- a/src/bspwm.h
++++ b/src/bspwm.h
+@@ -84,7 +84,7 @@ extern bool auto_raise;
+ extern bool sticky_still;
+ extern bool hide_sticky;
+ extern bool record_history;
+-extern bool running;
++extern volatile sig_atomic_t running;
+ extern bool restart;
+ extern bool randr;
+
+--
+2.47.1
+