X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fcreate.c;h=5027fce90dc1d8aca19f63566a7a6e4535b52489;hp=94c1c61836f5edd61dc5c4b8784d346875d0284b;hb=890d8fe47755c3bad936389cf48ffa141cff41c9;hpb=92360082fd291a95695fb612d773ae1bb991c256 diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c index 94c1c6183..5027fce90 100644 --- a/src/bin/lttng/commands/create.c +++ b/src/bin/lttng/commands/create.c @@ -15,7 +15,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#define _GNU_SOURCE #define _LGPL_SOURCE #include #include @@ -28,6 +27,7 @@ #include #include #include +#include #include @@ -80,7 +80,7 @@ static struct poptOption long_options[] = { * why this declaration exists and used ONLY in for this command. */ extern int _lttng_create_session_ext(const char *name, const char *url, - const char *datetime, int live_timer); + const char *datetime); /* * usage @@ -459,7 +459,7 @@ static int create_session(void) } ret = lttng_create_session_live(session_name, url, opt_live_timer); } else { - ret = _lttng_create_session_ext(session_name, url, datetime, -1); + ret = _lttng_create_session_ext(session_name, url, datetime); } if (ret < 0) { /* Don't set ret so lttng can interpret the sessiond error. */ @@ -562,14 +562,13 @@ static int spawn_sessiond(char *pathname) pid_t pid; MSG("Spawning a session daemon"); - recv_child_signal = 0; pid = fork(); if (pid == 0) { /* - * Spawn session daemon and tell - * it to signal us when ready. + * Spawn session daemon in daemon mode. */ - execlp(pathname, "lttng-sessiond", "--sig-parent", "--quiet", NULL); + execlp(pathname, "lttng-sessiond", + "--daemonize", NULL); /* execlp only returns if error happened */ if (errno == ENOENT) { ERR("No session daemon found. Use --sessiond-path."); @@ -579,25 +578,42 @@ static int spawn_sessiond(char *pathname) kill(getppid(), SIGTERM); /* wake parent */ exit(EXIT_FAILURE); } else if (pid > 0) { - sessiond_pid = pid; /* - * Wait for lttng-sessiond to start. We need to use a flag to check if - * the signal has been sent to us, because the child can be scheduled - * before the parent, and thus send the signal before this check. In - * the signal handler, we set the recv_child_signal flag, so anytime we - * check it after the fork is fine. Note that sleep() is interrupted - * before the 1 second delay as soon as the signal is received, so it - * will not cause visible delay for the user. + * In daemon mode (--daemonize), sessiond only exits when + * it's ready to accept commands. */ - while (!recv_child_signal) { - sleep(1); - } - /* - * The signal handler will nullify sessiond_pid on SIGCHLD - */ - if (!sessiond_pid) { - exit(EXIT_FAILURE); + for (;;) { + 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", + WTERMSIG(status)); + ret = -1; + goto end; + } else if (WIFEXITED(status)) { + DBG("Session daemon terminated normally (exit status: %d)", + WEXITSTATUS(status)); + + if (WEXITSTATUS(status) != 0) { + ERR("Session daemon terminated with an error (exit status: %d)", + WEXITSTATUS(status)); + ret = -1; + goto end; + } + break; + } } + goto end; } else { PERROR("fork"); @@ -658,10 +674,11 @@ static int launch_sessiond(void) } ret = spawn_sessiond(pathname); - if (ret < 0) { - ERR("Problem occurred when starting %s", pathname); - } end: + if (ret) { + ERR("Problem occurred while launching session daemon (%s)", + pathname); + } return ret; }