From: David Goulet Date: Fri, 27 May 2011 21:27:41 +0000 (-0400) Subject: Modify kconsumerd thread and spawning function X-Git-Tag: v2.0-pre1~99 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=712ea556b2774ad12e9a9a83c3d04eda46e3f9a0;p=lttng-tools.git Modify kconsumerd thread and spawning function In the kconsumerd thread, the one use case where the kconsumerd tells us he's ready but we are unable to connect is now validate using the kconsumerd_pid in the spawn_kconsumerd_thread function. Also, we do not iterate over and over on the error socket anymore. Upon receiving an error from the kconsumerd, this means that the daemon will quit and thus the thread is no longer necessary. Signed-off-by: David Goulet --- diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index 5327804c3..68481146e 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -332,6 +332,7 @@ static void *thread_manage_kconsumerd(void *data) goto error; } + /* Getting status code from kconsumerd */ ret = lttcomm_recv_unix_sock(sock, &code, sizeof(enum lttcomm_return_code)); if (ret <= 0) { goto error; @@ -340,6 +341,7 @@ static void *thread_manage_kconsumerd(void *data) if (code == KCONSUMERD_COMMAND_SOCK_READY) { kconsumerd_cmd_sock = lttcomm_connect_unix_sock(kconsumerd_cmd_unix_sock_path); if (kconsumerd_cmd_sock < 0) { + sem_post(&kconsumerd_sem); perror("kconsumerd connect"); goto error; } @@ -352,20 +354,15 @@ static void *thread_manage_kconsumerd(void *data) goto error; } - while (1) { - /* Wait for any kconsumerd error */ - ret = lttcomm_recv_unix_sock(sock, &code, sizeof(enum lttcomm_return_code)); - if (ret <= 0) { - ERR("Kconsumerd closed the command socket"); - goto error; - } - - ERR("Kconsumerd return code : %s", lttcomm_get_readable_code(-code)); - if (code != KCONSUMERD_POLL_HUP) { - goto error; - } + /* Wait for any kconsumerd error */ + ret = lttcomm_recv_unix_sock(sock, &code, sizeof(enum lttcomm_return_code)); + if (ret <= 0) { + ERR("Kconsumerd closed the command socket"); + goto error; } + ERR("Kconsumerd return code : %s", lttcomm_get_readable_code(-code)); + error: kconsumerd_pid = 0; DBG("Kconsumerd thread dying"); @@ -461,9 +458,15 @@ static int spawn_kconsumerd_thread(void) /* Wait for the kconsumerd thread to be ready */ sem_wait(&kconsumerd_sem); + if (kconsumerd_pid == 0) { + ERR("Kconsumerd did not start"); + goto error; + } + return 0; error: + ret = LTTCOMM_KERN_CONSUMER_FAIL; return ret; } @@ -535,11 +538,9 @@ static int start_kconsumerd(void) DBG("Kconsumerd pid %d", ret); DBG("Spawning kconsumerd thread"); - ret = spawn_kconsumerd_thread(); if (ret < 0) { ERR("Fatal error spawning kconsumerd thread"); - ret = LTTCOMM_FATAL; goto error; }