Jochen Sprickerhof wrote:
> * koneu <[email protected]> [2015-04-27 11:42]:
> > waitpid and WNOHANG is not the way to go though. Use wait
>
> Why? wait is just convenience for waitpid. Also, it didn't work for me.
> Can you send a patch if you think there is a better way to do it?
>
> > and check the pid against the shell's to decide whether to quit st.
>
> I do that, please read my patch.
Patch attached.
The whitespace change 2 lines later is intended to match st's style.
diff --git a/st.c b/st.c
index d954288..7bc0807 100644
--- a/st.c
+++ b/st.c
@@ -1238,12 +1238,16 @@ execsh(void) {
void
sigchld(int a) {
int stat, ret;
+ pid_t waitr;
- if(waitpid(pid, &stat, 0) < 0)
- die("Waiting for pid %hd failed: %s\n", pid, strerror(errno));
+ waitr = wait(&stat);
+ if(waitr < 0)
+ die("Waiting failed: %s\n", strerror(errno));
+ if(waitr != pid)
+ return;
ret = WIFEXITED(stat) ? WEXITSTATUS(stat) : EXIT_FAILURE;
- if (ret != EXIT_SUCCESS)
+ if(ret != EXIT_SUCCESS)
die("child finished with error '%d'\n", stat);
exit(EXIT_SUCCESS);
}