Modify kconsumerd thread and spawning function
authorDavid Goulet <david.goulet@polymtl.ca>
Fri, 27 May 2011 21:27:41 +0000 (17:27 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Fri, 27 May 2011 21:27:41 +0000 (17:27 -0400)
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 <david.goulet@polymtl.ca>
ltt-sessiond/main.c

index 5327804c33b3ec62fcfb6905f572bda798e97242..68481146eb1badc3bc30c2810448434013ac50a5 100644 (file)
@@ -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;
        }
 
This page took 0.028595 seconds and 4 git commands to generate.