Fix sigchld
authorJochen Sprickerhof <dwm@jochen.sprickerhof.de>
Wed, 22 Apr 2015 15:22:34 +0000 (17:22 +0200)
committerRoberto E. Vargas Caballero <k0ga@shike2.com>
Mon, 4 May 2015 08:57:40 +0000 (10:57 +0200)
Only wait for termination of the shell.

st.c

diff --git a/st.c b/st.c
index d954288..300cab6 100644 (file)
--- a/st.c
+++ b/st.c
@@ -1238,10 +1238,14 @@ execsh(void) {
 void
 sigchld(int a) {
        int stat, ret;
+       pid_t p;
 
-       if(waitpid(pid, &stat, 0) < 0)
+       if((p = waitpid(pid, &stat, WNOHANG)) < 0)
                die("Waiting for pid %hd failed: %s\n", pid, strerror(errno));
 
+       if(pid != p)
+               return;
+
        ret = WIFEXITED(stat) ? WEXITSTATUS(stat) : EXIT_FAILURE;
        if (ret != EXIT_SUCCESS)
                die("child finished with error '%d'\n", stat);