The Handler Ate Errno
A daemon reaps children from a SIGCHLD handler. The author knew about signal safety and deliberately used write instead of printf.
static void reap(int sig) {
static const char msg[] = "child exited\n";
write(STDERR_FILENO, msg, sizeof msg - 1);
while (waitpid(-1, NULL, WNOHANG) > 0)
;
}
Meanwhile the main loop does:
ssize_t n = recv(sock, buf, sizeof buf, 0);
if (n < 0) {
if (errno == EINTR) continue;
log_fatal("recv failed: %s", strerror(errno));
exit(1);
}
Occasionally the daemon dies with recv failed: No child processes. What is the defect?
Sign in to answer questions and track your progress
Sign In