Bladeren bron

handle child exit via POLLHUP instead of sigchld

this fix a racecondition which leads to wrong return code.
Jan Klemkow 5 jaren geleden
bovenliggende
commit
97b9041489
1 gewijzigde bestanden met toevoegingen van 2 en 19 verwijderingen
  1. 2 19
      scroll.c

+ 2 - 19
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);
 }