X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=ltt-sessiond%2Fmain.c;h=436ee9f167e8a45853fe9b58557555de74b82629;hp=85ac06be9e32c2967417513b7902d2b226b303ba;hb=733bb3da0f1ef5005ffe5df7811875e737cb3414;hpb=0fdd1e2c4a9f725daed3f91dd4f5609ae54ebe93 diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index 85ac06be9..436ee9f16 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -880,6 +880,15 @@ static int update_apps_cmd_pollfd(unsigned int nb_fd, unsigned int old_nb_fd, } } + if (nb_fd < 2) { + /* + * There should *always* be at least two fds in the pollfd. This safety + * check make sure the poll() will actually try on those two pipes at + * best which are the thread_quit_pipe and apps_cmd_pipe. + */ + nb_fd = 2; + } + /* Destroy old pollfd */ free(old_pollfd); @@ -899,7 +908,7 @@ error: */ static void *thread_manage_apps(void *data) { - int i, ret, count; + int i, ret, current_nb_fd; unsigned int nb_fd = 2; int update_poll_flag = 1; struct pollfd *pollfd = NULL; @@ -908,6 +917,7 @@ static void *thread_manage_apps(void *data) DBG("[thread] Manage application started"); ust_cmd.sock = -1; + current_nb_fd = nb_fd; while (1) { /* See if we have a valid socket to add to pollfd */ @@ -918,7 +928,7 @@ static void *thread_manage_apps(void *data) /* The pollfd struct must be updated */ if (update_poll_flag) { - ret = update_apps_cmd_pollfd(nb_fd, ARRAY_SIZE(pollfd), &pollfd); + ret = update_apps_cmd_pollfd(nb_fd, current_nb_fd, &pollfd); if (ret < 0) { /* malloc failed so we quit */ goto error; @@ -978,8 +988,8 @@ static void *thread_manage_apps(void *data) } } - count = nb_fd; - for (i = 2; i < count; i++) { + current_nb_fd = nb_fd; + for (i = 2; i < current_nb_fd; i++) { /* Apps socket is closed/hungup */ switch (pollfd[i].revents) { case POLLERR: @@ -994,7 +1004,7 @@ static void *thread_manage_apps(void *data) } } - if (nb_fd != count) { + if (nb_fd != current_nb_fd) { update_poll_flag = 1; } }