From 8b66b00d8b2362d6799d7fad1920e65339e2e5e8 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 28 Dec 2015 18:08:20 +0100 Subject: reap children in sighandler to avoid getting stuck at EAGAIN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/satd-diminished.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/satd-diminished.c b/src/satd-diminished.c index f2e039f..187ad6a 100644 --- a/src/satd-diminished.c +++ b/src/satd-diminished.c @@ -87,7 +87,16 @@ static volatile sig_atomic_to received_signo = 0; */ static void sighander(int signo) { - received_signo = (sig_atomic_to)signo; + int saved_errno = errno; + switch (signo) { + case SIGCHLD: + waitpid(-1, NULL, WNOHANG); + break; + default: + received_signo = (sig_atomic_to)signo; + break; + } + errno = saved_errno; } @@ -126,7 +135,6 @@ main(int argc, char *argv[], char *envp[]) /* The magnificent loop. */ accept_again: - while (waitpid(-1, NULL, WNOHANG) > 0); if (received_signo == SIGHUP) { execve(DAEMON_PREFIX "diminished", argv, envp); perror(argv[0]); -- cgit v1.2.3-70-g09d2