commit 5ad2174cf95887351c3dd97f6d6c29eb460e1f24
parent bda5b50b99fa06739fb2d370ff033bff54703108
Author: bakkeby <bakkeby@gmail.com>
Date: Mon, 20 Apr 2020 12:43:04 +0200
[st][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).
Diffstat:
3 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
@@ -15,7 +15,7 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the
### Changelog:
-2020-04-20 - Added the force redraw on pselect after key is pressed patch
+2020-04-20 - Added the force redraw on pselect after key is pressed patch and the externalpipe sigaction patch
2020-03-29 - Added invert and workingdir patches
@@ -60,6 +60,9 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the
- [externalpipe](https://st.suckless.org/patches/externalpipe/)
- this patch allows for eading and writing st's screen through a pipe, e.g. to pass info to dmenu
+ - [externalpipe-sigaction](https://lists.suckless.org/hackers/2004/17216.html)
+ - this patch prevents the reset of the signal handler set on SIGCHILD, when the forked process that executes the external process exits
+
- [~fixime~](https://st.suckless.org/patches/fix_ime/)
- adds better Input Method Editor (IME) support
- (included in the base as per [35f7db](https://git.suckless.org/st/commit/e85b6b64660214121164ea97fb098eaa4935f7db.html))
diff --git a/patches.def.h b/patches.def.h
@@ -68,6 +68,13 @@
*/
#define EXTERNALPIPE_PATCH 0
+/* This patch prevents the reset of the signal handler set on SIGCHILD, when
+ * the forked process that executes the external process exits.
+ * This patch depends on EXTERNALPIPE_PATCH being enabled.
+ * https://lists.suckless.org/hackers/2004/17216.html
+ */
+#define EXTERNALPIPE_SIGACTION_PATCH 0
+
/* This patch allows command line applications to use all the fancy key combinations
* that are available to GUI applications.
* https://st.suckless.org/patches/fix_keyboard_input/
diff --git a/st.c b/st.c
@@ -782,7 +782,11 @@ sigchld(int a)
int stat;
pid_t p;
+ #if EXTERNALPIPE_SIGACTION_PATCH && EXTERNALPIPE_PATCH
+ if ((p = waitpid(-1, &stat, WNOHANG)) < 0)
+ #else
if ((p = waitpid(pid, &stat, WNOHANG)) < 0)
+ #endif // EXTERNALPIPE_SIGACTION_PATCH
die("waiting for pid %hd failed: %s\n", pid, strerror(errno));
if (pid != p)
@@ -823,6 +827,9 @@ int
ttynew(char *line, char *cmd, char *out, char **args)
{
int m, s;
+ #if EXTERNALPIPE_SIGACTION_PATCH && EXTERNALPIPE_PATCH
+ struct sigaction sa;
+ #endif // EXTERNALPIPE_SIGACTION_PATCH
if (out) {
term.mode |= MODE_PRINT;
@@ -878,7 +885,14 @@ ttynew(char *line, char *cmd, char *out, char **args)
#endif
close(s);
cmdfd = m;
+ #if EXTERNALPIPE_SIGACTION_PATCH && EXTERNALPIPE_PATCH
+ memset(&sa, 0, sizeof(sa));
+ sigemptyset(&sa.sa_mask);
+ sa.sa_handler = sigchld;
+ sigaction(SIGCHLD, &sa, NULL);
+ #else
signal(SIGCHLD, sigchld);
+ #endif // EXTERNALPIPE_SIGACTION_PATCH
break;
}
return cmdfd;