Fix kconsumerd multiple spawn bug
authorDavid Goulet <david.goulet@polymtl.ca>
Wed, 1 Jun 2011 21:29:21 +0000 (17:29 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Wed, 1 Jun 2011 21:29:21 +0000 (17:29 -0400)
The kconsumerd thread was spawned even if there was already an existing
kconsumerd thread.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
ltt-sessiond/main.c

index 30b0edd0e75f6d6e46272fa9b98b807495c6c2ac..97db535d142b16f802e9e80c77a19ef094097d5a 100644 (file)
@@ -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:
This page took 0.027068 seconds and 4 git commands to generate.