From: Jérémie Galarneau Date: Thu, 24 Sep 2015 16:34:49 +0000 (-0400) Subject: Fix: Handle EINTR of waitpid when spawning a session daemon X-Git-Tag: v2.8.0-rc1~300 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=81527d36f84a02110360f0332f3b35f2d3024d17;hp=034a784813438dd99cfd1c1ea2fc9ee713dad345;ds=sidebyside Fix: Handle EINTR of waitpid when spawning a session daemon waitpid may fail for various reasons, being interrupted being the most frequent. In such a case, status is left uninitialized which results in the WIFSIGNALED and WIFEXITED macros returning undefined value, resulting in surprising logging statements such as "killed by signal 114". Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c index a7d327fbc..abc5cb9b8 100644 --- a/src/bin/lttng/commands/create.c +++ b/src/bin/lttng/commands/create.c @@ -579,14 +579,22 @@ static int spawn_sessiond(char *pathname) kill(getppid(), SIGTERM); /* wake parent */ exit(EXIT_FAILURE); } else if (pid > 0) { - int status; - /* * In daemon mode (--daemonize), sessiond only exits when * it's ready to accept commands. */ for (;;) { - waitpid(pid, &status, 0); + int status; + pid_t wait_pid_ret = waitpid(pid, &status, 0); + + if (wait_pid_ret < 0) { + if (errno == EINTR) { + continue; + } + PERROR("waitpid"); + ret = -errno; + goto end; + } if (WIFSIGNALED(status)) { ERR("Session daemon was killed by signal %d",