commit 97b90414891e957c95caffe078c69b18aa38e659
Author: Jan Klemkow <[email protected]>
AuthorDate: Fri Apr 17 21:46:55 2020 +0200
Commit: Jan Klemkow <[email protected]>
CommitDate: Fri Apr 17 21:46:55 2020 +0200
handle child exit via POLLHUP instead of sigchld
this fix a racecondition which leads to wrong return code.
diff --git a/scroll.c b/scroll.c
index 3952a54..3219915 100644
--- a/scroll.c
+++ b/scroll.c
@@ -89,19 +89,6 @@ die(const char *fmt, ...)
exit(EXIT_FAILURE);
}
-void
-sigchld(int sig)
-{
- pid_t pid;
- int status;
-
- assert(sig == SIGCHLD);
-
- while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
- if (pid == child)
- exit(WEXITSTATUS(status));
-}
-
void
sigwinch(int sig)
{
@@ -421,8 +408,6 @@ main(int argc, char *argv[])
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0)
die("ioctl:");
- if (signal(SIGCHLD, sigchld) == SIG_ERR)
- die("signal:");
if (signal(SIGWINCH, sigwinch) == SIG_ERR)
die("signal:");
@@ -553,11 +538,9 @@ main(int argc, char *argv[])
if (close(mfd) == -1)
die("close:");
- pid_t pid;
int status;
- while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
- if (pid != child)
- continue;
+ if (waitpid(child, &status, 0) == -1)
+ die("waitpid:");
return WEXITSTATUS(status);
}