Refactor sigchld_cb(), handle EINTR properly, restart waitpid()

The waitpid() function can return -1 due to EINTR (signal), so we should
restart it to make sure we collect all zombies.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2021-06-02 16:34:24 +02:00
parent 6eccca31b9
commit 41a14391a2
+9 -5
View File
@@ -403,13 +403,17 @@ static void sigchld_cb(uev_t *w, void *arg, int events)
}
/* Reap all the children! */
do {
while (1) {
pid = waitpid(-1, &status, WNOHANG);
if (pid > 0) {
_d("Collected child %d", pid);
service_monitor(pid, status);
if (pid <= 0) {
if (pid == -1 && errno == EINTR)
continue;
break;
}
} while (pid > 0);
_d("Collected child %d", pid);
service_monitor(pid, status);
}
}
/*