Fix: Handle EINTR of waitpid when spawning a session daemon
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 24 Sep 2015 16:34:49 +0000 (12:34 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 24 Sep 2015 16:34:49 +0000 (12:34 -0400)
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 <jeremie.galarneau@efficios.com>
src/bin/lttng/commands/create.c

index a7d327fbcada361477b71f44d025595adba67056..abc5cb9b8e1133170bb9df9fa4f93ec36676f737 100644 (file)
@@ -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",
This page took 0.034236 seconds and 4 git commands to generate.