From 4282f9a3d51a8db6a6cc602f11d42ee9a5a0c686 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Tue, 25 Feb 2014 13:55:12 -0500 Subject: [PATCH] Fix: report error if consumer can't be spawned On error of the UST consumer execl(), we now exit the forked process like the kernel does. Furthermore, fix an error handling value when timing out when waiting for the consumer to bootstrap thus returning an error to the client and not continuing with the command thinking that the consumer was actually spawned. So, the expected behavior is to wait for the pthread condition and if a timeout is seen, the client is informed thus making the client command hang for the default timeout value of 30 seconds. Fixes #702 Signed-off-by: David Goulet --- src/bin/lttng-sessiond/main.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index f0aaf73b0..f40c52487 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -2151,19 +2151,23 @@ static int spawn_consumer_thread(struct consumer_data *consumer_data) if (ret != 0) { errno = ret; if (ret == ETIMEDOUT) { + int pth_ret; + /* * Call has timed out so we kill the kconsumerd_thread and return * an error. */ ERR("Condition timed out. The consumer thread was never ready." " Killing it"); - ret = pthread_cancel(consumer_data->thread); - if (ret < 0) { + pth_ret = pthread_cancel(consumer_data->thread); + if (pth_ret < 0) { PERROR("pthread_cancel consumer thread"); } } else { PERROR("pthread_cond_wait failed consumer thread"); } + /* Caller is expecting a negative value on failure. */ + ret = -1; goto error; } @@ -2249,10 +2253,11 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) consumer_to_use = consumerd32_bin; } else { DBG("Could not find any valid consumerd executable"); + ret = -EINVAL; break; } DBG("Using kernel consumer at: %s", consumer_to_use); - execl(consumer_to_use, + ret = execl(consumer_to_use, "lttng-consumerd", verbosity, "-k", "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path, "--consumerd-err-sock", consumer_data->err_unix_sock_path, @@ -2300,9 +2305,6 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) if (consumerd64_libdir[0] != '\0') { free(tmpnew); } - if (ret) { - goto error; - } break; } case LTTNG_CONSUMER32_UST: @@ -2346,9 +2348,6 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) if (consumerd32_libdir[0] != '\0') { free(tmpnew); } - if (ret) { - goto error; - } break; } default: @@ -2356,8 +2355,9 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) exit(EXIT_FAILURE); } if (errno != 0) { - PERROR("kernel start consumer exec"); + PERROR("Consumer execl()"); } + /* Reaching this point, we got a failure on our execl(). */ exit(EXIT_FAILURE); } else if (pid > 0) { ret = pid; -- 2.34.1