[wiki] [sites] Prevent reset of SIGCHILD handler to default || Christian Tenllado

From: <git_AT_suckless.org>
Date: Mon, 04 May 2020 19:55:08 +0200

commit 42d5e4b900e346ffded7f89501ecd530808f07ac
Author: Christian Tenllado <ctenllado_AT_gmail.com>
Date: Mon May 4 19:52:27 2020 +0200

    Prevent reset of SIGCHILD handler to default
    
    This patch fixes a bug in the externalpipe patch, and should be applied
    on top of it. It prevents the reset of the signal handler set on
    SIGCHILD, when the forked process that executes the external process
    exits. I opted for switching from signal to sigaction instead of
    rearming the signal in the sigchld function, just because it is the
    recommended function (although I tried both ways and both worked).

diff --git a/st.suckless.org/patches/externalpipe/st-externalpipe-sigaction-20200418-30e1771.diff b/st.suckless.org/patches/externalpipe/st-externalpipe-sigaction-20200418-30e1771.diff
new file mode 100644
index 00000000..b0b6fd54
--- /dev/null
+++ b/st.suckless.org/patches/externalpipe/st-externalpipe-sigaction-20200418-30e1771.diff
_AT_@ -0,0 +1,51 @@
+From 103531d8ecaf98322a45d956bc13f9da5cd68853 Mon Sep 17 00:00:00 2001
+From: Christian Tenllado <ctenllado_AT_gmail.com>
+Date: Sat, 18 Apr 2020 20:45:40 +0200
+Subject: [PATCH] externalpipe sigaction
+
+This patch should be applied on top of the externalpipe patch. It
+prevents the reset of the signal handler set on SIGCHILD, when the
+forked process that executes the external process exits. I opted for
+switching from signal to sigaction instead of rearming the signal in the
+sigchld function, just because it is the recommended function (although I
+tried both ways and both worked).
+---
+ st.c | 8 ++++++--
+ 1 file changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/st.c b/st.c
+index ab291ac..0824894 100644
+--- a/st.c
++++ b/st.c
+_AT_@ -712,7 +712,7 @@ sigchld(int a)
+ int stat;
+ pid_t p;
+
+- if ((p = waitpid(pid, &stat, WNOHANG)) < 0)
++ if ((p = waitpid(-1, &stat, WNOHANG)) < 0)
+ die("waiting for pid %hd failed: %s
", pid, strerror(errno));
+
+ if (pid != p)
+_AT_@ -753,6 +753,7 @@ int
+ ttynew(char *line, char *cmd, char *out, char **args)
+ {
+ int m, s;
++ struct sigaction sa;
+
+ if (out) {
+ term.mode |= MODE_PRINT;
+_AT_@ -804,7 +805,10 @@ ttynew(char *line, char *cmd, char *out, char **args)
+ #endif
+ close(s);
+ cmdfd = m;
+- signal(SIGCHLD, sigchld);
++ memset(&sa, 0, sizeof(sa));
++ sigemptyset(&sa.sa_mask);
++ sa.sa_handler = sigchld;
++ sigaction(SIGCHLD, &sa, NULL);
+ break;
+ }
+ return cmdfd;
+--
+2.20.1
+
Received on Mon May 04 2020 - 19:55:08 CEST

This archive was generated by hypermail 2.3.0 : Mon May 04 2020 - 20:00:55 CEST