From: David Goulet Date: Wed, 1 Oct 2014 18:16:07 +0000 (-0400) Subject: Fix: bad handling of incoming data in consumer thread X-Git-Tag: v2.4.3~49 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=ef1917cfb80b8fcc1b4cecf28d8a9904c29914be;p=lttng-tools.git Fix: bad handling of incoming data in consumer thread This will fix Coverity issue 1019892. The issue uncovered a more serious problem. The loop on ready FDs of the thread was exiting at each branch thus not going on all fd. This is problematic when the thread quit pipe is triggered and when there is also at the same time a request for metadata from the consumer since the metadata request could have been ignored. This patch makes sure we go through all FDs in the loop when the thread quit pipe or the metadata fd is triggered. Signed-off-by: David Goulet --- diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 14dd1381a..a95f269d0 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -1028,7 +1028,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; @@ -1186,6 +1186,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(); @@ -1208,12 +1217,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 */ @@ -1242,11 +1251,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(); }