Change SIGCHLD to SIGUSR1 when lttng waiting on sessiond
authorDavid Goulet <dgoulet@efficios.com>
Mon, 23 Jan 2012 19:12:46 +0000 (14:12 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Mon, 23 Jan 2012 19:12:46 +0000 (14:12 -0500)
Using lttng cli, if the session daemon dies after exec(), a SIGCHLD is
returned. It was catched but not handled to cleanly quit and inform the
user that the session daemon failed.

We now use SIGUSR1 to signal the lttng cli that the session daemon is
ready to receive command.

Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-sessiond/main.c
src/bin/lttng/lttng.c

index 886456a0ce8ce56f37867fd2a7b04871f5e813fa..7da0b7c686c314010bfd5106620e1892809b88c5 100644 (file)
@@ -3541,7 +3541,7 @@ static void *thread_manage_clients(void *data)
         * Notify parent pid that we are ready to accept command for client side.
         */
        if (opt_sig_parent) {
-               kill(ppid, SIGCHLD);
+               kill(ppid, SIGUSR1);
        }
 
        while (1) {
index 2ee93253fe7b50f7ddfc139c58bde769465ec09c..7058dd529d1ecd73e3a191f84e08b0883b54628e 100644 (file)
@@ -22,6 +22,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 #include <unistd.h>
 #include <config.h>
 
@@ -37,6 +39,7 @@ int opt_quiet;
 int opt_verbose;
 static int opt_no_sessiond;
 static char *opt_sessiond_path;
+static pid_t sessiond_pid;
 
 enum {
        OPT_SESSION_PATH,
@@ -168,14 +171,23 @@ static void clean_exit(int code)
  */
 static void sighandler(int sig)
 {
+       int status;
+
        switch (sig) {
                case SIGTERM:
                        DBG("SIGTERM caugth");
                        clean_exit(EXIT_FAILURE);
                        break;
                case SIGCHLD:
-                       /* Notify is done */
                        DBG("SIGCHLD caugth");
+                       waitpid(sessiond_pid, &status, 0);
+                       /* Indicate that the session daemon died */
+                       sessiond_pid = 0;
+                       ERR("Session daemon died (exit status %d)", WEXITSTATUS(status));
+                       break;
+               case SIGUSR1:
+                       /* Notify is done */
+                       DBG("SIGUSR1 caugth");
                        break;
                default:
                        DBG("Unknown signal %d caugth", sig);
@@ -204,7 +216,7 @@ static int set_signal_handler(void)
        sa.sa_handler = sighandler;
        sa.sa_mask = sigset;
        sa.sa_flags = 0;
-       if ((ret = sigaction(SIGCHLD, &sa, NULL)) < 0) {
+       if ((ret = sigaction(SIGUSR1, &sa, NULL)) < 0) {
                perror("sigaction");
                goto end;
        }
@@ -214,6 +226,11 @@ static int set_signal_handler(void)
                goto end;
        }
 
+       if ((ret = sigaction(SIGCHLD, &sa, NULL)) < 0) {
+               perror("sigaction");
+               goto end;
+       }
+
 end:
        return ret;
 }
@@ -296,8 +313,12 @@ static int spawn_sessiond(char *pathname)
                kill(getppid(), SIGTERM);       /* unpause parent */
                exit(EXIT_FAILURE);
        } else if (pid > 0) {
+               sessiond_pid = pid;
                /* Wait for lttng-sessiond to start */
                pause();
+               if (!sessiond_pid) {
+                       exit(EXIT_FAILURE);
+               }
                goto end;
        } else {
                perror("fork");
This page took 0.028695 seconds and 4 git commands to generate.