From 81527d36f84a02110360f0332f3b35f2d3024d17 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 24 Sep 2015 12:34:49 -0400 Subject: [PATCH 1/1] Fix: Handle EINTR of waitpid when spawning a session daemon MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- src/bin/lttng/commands/create.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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", -- 2.34.1