X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Flttng.c;h=64f3efa446530ed61663c9434eb77251cc923c91;hp=2ee93253fe7b50f7ddfc139c58bde769465ec09c;hb=679b4943c3b0f451e7f4fbcd804dd8a7a679e253;hpb=db7586006bc1a2b9057a2c108bf1e7d20fd6903f diff --git a/src/bin/lttng/lttng.c b/src/bin/lttng/lttng.c index 2ee93253f..64f3efa44 100644 --- a/src/bin/lttng/lttng.c +++ b/src/bin/lttng/lttng.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #include @@ -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; } @@ -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"); @@ -359,15 +377,19 @@ end: } /* - * Check for the "help" option in the argv. If found, return 1 else return 0. + * Check args for specific options that *must* not trigger a session daemon + * execution. + * + * Return 1 if match else 0. */ -static int check_help_command(int argc, char **argv) +static int check_args_no_sessiond(int argc, char **argv) { int i; for (i = 0; i < argc; i++) { if ((strncmp(argv[i], "-h", 2) == 0) || - strncmp(argv[i], "--h", 3) == 0) { + strncmp(argv[i], "--h", 3) == 0 || + strncmp(argv[i], "--list-options", 14)) { return 1; } } @@ -430,7 +452,7 @@ static int parse_args(int argc, char **argv) } /* Spawn session daemon if needed */ - if (opt_no_sessiond == 0 && check_help_command(argc, argv) == 0 && + if (opt_no_sessiond == 0 && check_args_no_sessiond(argc, argv) == 0 && (check_sessiond() < 0)) { goto error; }