st-externalpipe-sigaction-20200418-30e1771.diff - sites - public wiki contents … | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
st-externalpipe-sigaction-20200418-30e1771.diff (1428B) | |
--- | |
1 From 103531d8ecaf98322a45d956bc13f9da5cd68853 Mon Sep 17 00:00:00 2001 | |
2 From: Christian Tenllado <[email protected]> | |
3 Date: Sat, 18 Apr 2020 20:45:40 +0200 | |
4 Subject: [PATCH] externalpipe sigaction | |
5 | |
6 This patch should be applied on top of the externalpipe patch. It | |
7 prevents the reset of the signal handler set on SIGCHILD, when the | |
8 forked process that executes the external process exits. I opted for | |
9 switching from signal to sigaction instead of rearming the signal in the | |
10 sigchld function, just because it is the recommended function (although I | |
11 tried both ways and both worked). | |
12 --- | |
13 st.c | 8 ++++++-- | |
14 1 file changed, 6 insertions(+), 2 deletions(-) | |
15 | |
16 diff --git a/st.c b/st.c | |
17 index ab291ac..0824894 100644 | |
18 --- a/st.c | |
19 +++ b/st.c | |
20 @@ -712,7 +712,7 @@ sigchld(int a) | |
21 int stat; | |
22 pid_t p; | |
23 | |
24 - if ((p = waitpid(pid, &stat, WNOHANG)) < 0) | |
25 + if ((p = waitpid(-1, &stat, WNOHANG)) < 0) | |
26 die("waiting for pid %hd failed: %s\n", pid, strerror(e… | |
27 | |
28 if (pid != p) | |
29 @@ -753,6 +753,7 @@ int | |
30 ttynew(char *line, char *cmd, char *out, char **args) | |
31 { | |
32 int m, s; | |
33 + struct sigaction sa; | |
34 | |
35 if (out) { | |
36 term.mode |= MODE_PRINT; | |
37 @@ -804,7 +805,10 @@ ttynew(char *line, char *cmd, char *out, char **arg… | |
38 #endif | |
39 close(s); | |
40 cmdfd = m; | |
41 - signal(SIGCHLD, sigchld); | |
42 + memset(&sa, 0, sizeof(sa)); | |
43 + sigemptyset(&sa.sa_mask); | |
44 + sa.sa_handler = sigchld; | |
45 + sigaction(SIGCHLD, &sa, NULL); | |
46 break; | |
47 } | |
48 return cmdfd; | |
49 -- | |
50 2.20.1 | |
51 |