From: David Goulet Date: Wed, 1 Jun 2011 21:29:21 +0000 (-0400) Subject: Fix kconsumerd multiple spawn bug X-Git-Tag: v2.0-pre1~93 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=c49dc785799508e445e3e386c87f8151eef3c34c;p=lttng-tools.git Fix kconsumerd multiple spawn bug The kconsumerd thread was spawned even if there was already an existing kconsumerd thread. Signed-off-by: David Goulet --- diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index 30b0edd0e..97db535d1 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -486,6 +486,8 @@ static pid_t spawn_kconsumerd(void) int ret; pid_t pid; + DBG("Spawning kconsumerd"); + pid = fork(); if (pid == 0) { /* @@ -518,21 +520,21 @@ static int start_kconsumerd(void) { int ret; - DBG("Spawning kconsumerd"); - pthread_mutex_lock(&kconsumerd_pid_mutex); - if (kconsumerd_pid == 0) { - ret = spawn_kconsumerd(); - if (ret < 0) { - ERR("Spawning kconsumerd failed"); - ret = LTTCOMM_KERN_CONSUMER_FAIL; - pthread_mutex_unlock(&kconsumerd_pid_mutex); - goto error; - } + if (kconsumerd_pid != 0) { + goto end; + } - /* Setting up the global kconsumerd_pid */ - kconsumerd_pid = ret; + ret = spawn_kconsumerd(); + if (ret < 0) { + ERR("Spawning kconsumerd failed"); + ret = LTTCOMM_KERN_CONSUMER_FAIL; + pthread_mutex_unlock(&kconsumerd_pid_mutex); + goto error; } + + /* Setting up the global kconsumerd_pid */ + kconsumerd_pid = ret; pthread_mutex_unlock(&kconsumerd_pid_mutex); DBG("Kconsumerd pid %d", ret); @@ -544,6 +546,8 @@ static int start_kconsumerd(void) goto error; } +end: + pthread_mutex_unlock(&kconsumerd_pid_mutex); return 0; error: