summaryrefslogtreecommitdiff
path: root/src/activate/activate.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-04-06 10:46:47 +0200
committerLennart Poettering <lennart@poettering.net>2016-04-06 10:46:47 +0200
commitd35da3ae6a8032002adbbd0d7d8338355f7ecf35 (patch)
treef3b41d66787d8cae2466320ad26c3d6b7cb3e0dc /src/activate/activate.c
parent0c0d058325d6548a8c5acd1fb9e5dbc229f93e00 (diff)
parent5488e52d285314c7535c87ee9aecadbc169db006 (diff)
Merge pull request #2961 from evverx/fix-activate-sigchld
activate: improve SIGCHLD handler
Diffstat (limited to 'src/activate/activate.c')
-rw-r--r--src/activate/activate.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/activate/activate.c b/src/activate/activate.c
index 8ac8dd8e72..a0cfc22000 100644
--- a/src/activate/activate.c
+++ b/src/activate/activate.c
@@ -316,19 +316,31 @@ static int do_accept(const char* name, char **argv, char **envp, int fd) {
}
/* SIGCHLD handler. */
-static void sigchld_hdl(int sig, siginfo_t *t, void *data) {
+static void sigchld_hdl(int sig) {
PROTECT_ERRNO;
- log_info("Child %d died with code %d", t->si_pid, t->si_status);
+ for (;;) {
+ siginfo_t si;
+ int r;
- /* Wait for a dead child. */
- (void) waitpid(t->si_pid, NULL, 0);
+ si.si_pid = 0;
+ r = waitid(P_ALL, 0, &si, WEXITED|WNOHANG);
+ if (r < 0) {
+ if (errno != ECHILD)
+ log_error_errno(errno, "Failed to reap children: %m");
+ return;
+ }
+ if (si.si_pid == 0)
+ return;
+
+ log_info("Child %d died with code %d", si.si_pid, si.si_status);
+ }
}
static int install_chld_handler(void) {
static const struct sigaction act = {
- .sa_flags = SA_SIGINFO,
- .sa_sigaction = sigchld_hdl,
+ .sa_flags = SA_NOCLDSTOP,
+ .sa_handler = sigchld_hdl,
};
int r;