X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=st.c;h=300cab631d76ead7242c23e3a0b06162427bd19c;hb=07ce96a3a0f4a650933f5f586082cbf2064ea2c1;hp=d954288508f8432fae0efd78749e467931973bea;hpb=190b94c7a2a7bb2f5d55cbb6eb1779fd042c6467;p=st.git diff --git a/st.c b/st.c index d954288..300cab6 100644 --- 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);