Fix: bad handling of incoming data in consumer thread
[lttng-tools.git] / src / bin / lttng-sessiond / main.c
index e5054735efd6279aec0fe5648a122dca3f366943..fa09758baa7083ed1a0b5c660fdf9f2e2b9ef03c 100644 (file)
@@ -1116,7 +1116,7 @@ static void signal_consumer_condition(struct consumer_data *data, int state)
  */
 static void *thread_manage_consumer(void *data)
 {
-       int sock = -1, i, ret, pollfd, err = -1;
+       int sock = -1, i, ret, pollfd, err = -1, should_quit = 0;
        uint32_t revents, nb_fd;
        enum lttcomm_return_code code;
        struct lttng_poll_event events;
@@ -1274,6 +1274,15 @@ restart:
        /* Infinite blocking call, waiting for transmission */
 restart_poll:
        while (1) {
+               health_code_update();
+
+               /* Exit the thread because the thread quit pipe has been triggered. */
+               if (should_quit) {
+                       /* Not a health error. */
+                       err = 0;
+                       goto exit;
+               }
+
                health_poll_entry();
                ret = lttng_poll_wait(&events, -1);
                health_poll_exit();
@@ -1296,12 +1305,12 @@ restart_poll:
 
                        health_code_update();
 
-                       /* Thread quit pipe has been closed. Killing thread. */
-                       ret = sessiond_check_thread_quit_pipe(pollfd, revents);
-                       if (ret) {
-                               err = 0;
-                               goto exit;
-                       }
+                       /*
+                        * Thread quit pipe has been triggered, flag that we should stop
+                        * but continue the current loop to handle potential data from
+                        * consumer.
+                        */
+                       should_quit = sessiond_check_thread_quit_pipe(pollfd, revents);
 
                        if (pollfd == sock) {
                                /* Event on the consumerd socket */
@@ -1330,11 +1339,8 @@ restart_poll:
                                        ERR("Handling metadata request");
                                        goto error;
                                }
-                               break;
-                       } else {
-                               ERR("Unknown pollfd");
-                               goto error;
                        }
+                       /* No need for an else branch all FDs are tested prior. */
                }
                health_code_update();
        }
@@ -5230,10 +5236,12 @@ int main(int argc, char **argv)
                /* Setup kernel tracer */
                if (!opt_no_kernel) {
                        init_kernel_tracer();
-                       ret = syscall_init_table();
-                       if (ret < 0) {
-                               ERR("Unable to populate syscall table. Syscall tracing won't"
-                                               " work for this session daemon.");
+                       if (kernel_tracer_fd >= 0) {
+                               ret = syscall_init_table();
+                               if (ret < 0) {
+                                       ERR("Unable to populate syscall table. Syscall tracing"
+                                                       " won't work for this session daemon.");
+                               }
                        }
                }
 
This page took 0.02557 seconds and 5 git commands to generate.