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.
@@ -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) {
+ if (pid <= 0) {
+ if (pid == -1 && errno == EINTR)
+ continue;
+ break;
+ }
+
_d("Collected child %d", pid);
service_monitor(pid, status);
}
- } while (pid > 0);
}
/*
