X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbin%2Flttng%2Flttng.c;h=031b015efba4dd05da900b25a8d0c8ead4dfa7b7;hb=fd4dfcecf4a21f7797d350e8dcd291c6f0c64e86;hp=a76a869a2b293c88b07149d53608d7baf8ffda47;hpb=c399183f4b3257c43915f3d81f44befd23165ad9;p=lttng-tools.git diff --git a/src/bin/lttng/lttng.c b/src/bin/lttng/lttng.c index a76a869a2..031b015ef 100644 --- a/src/bin/lttng/lttng.c +++ b/src/bin/lttng/lttng.c @@ -22,11 +22,13 @@ #include #include #include +#include +#include #include #include #include -#include +#include #include "command.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,17 +171,26 @@ static void clean_exit(int code) */ static void sighandler(int sig) { + int status; + switch (sig) { case SIGTERM: - DBG("SIGTERM catched"); + DBG("SIGTERM caugth"); clean_exit(EXIT_FAILURE); break; case SIGCHLD: + 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("SIGCHLD catched"); + DBG("SIGUSR1 caugth"); break; default: - DBG("Unknown signal %d catched", sig); + DBG("Unknown signal %d caugth", sig); break; } @@ -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; } @@ -246,9 +263,6 @@ static int handle_command(int argc, char **argv) case CMD_ERROR: ERR("Command error"); break; - case CMD_NOT_IMPLEMENTED: - ERR("Options not implemented"); - break; case CMD_UNDEFINED: ERR("Undefined command"); break; @@ -296,8 +310,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");