Fix: poll: show the correct number of fds
[lttng-tools.git] / src / bin / lttng-sessiond / main.c
index bc3a6bb445735baf9937ab699be70cab02c3a11c..e084aba61437961fe0f2d505bef57ed0f991c283 100644 (file)
@@ -1059,12 +1059,14 @@ static void *thread_manage_kernel(void *data)
                        update_poll_flag = 0;
                }
 
-               DBG("Thread kernel polling on %d fds", LTTNG_POLL_GETNB(&events));
+               DBG("Thread kernel polling");
 
                /* Poll infinite value of time */
        restart:
                health_poll_entry();
                ret = lttng_poll_wait(&events, -1);
+               DBG("Thread kernel return from poll on %d fds",
+                               LTTNG_POLL_GETNB(&events));
                health_poll_exit();
                if (ret < 0) {
                        /*
@@ -1090,6 +1092,11 @@ static void *thread_manage_kernel(void *data)
 
                        health_code_update();
 
+                       if (!revents) {
+                               /* No activity for this FD (poll implementation). */
+                               continue;
+                       }
+
                        /* Thread quit pipe has been closed. Killing thread. */
                        ret = sessiond_check_thread_quit_pipe(pollfd, revents);
                        if (ret) {
@@ -1235,6 +1242,11 @@ restart:
 
                health_code_update();
 
+               if (!revents) {
+                       /* No activity for this FD (poll implementation). */
+                       continue;
+               }
+
                /* Thread quit pipe has been closed. Killing thread. */
                ret = sessiond_check_thread_quit_pipe(pollfd, revents);
                if (ret) {
@@ -1362,6 +1374,11 @@ restart_poll:
 
                        health_code_update();
 
+                       if (!revents) {
+                               /* No activity for this FD (poll implementation). */
+                               continue;
+                       }
+
                        /*
                         * Thread quit pipe has been triggered, flag that we should stop
                         * but continue the current loop to handle potential data from
@@ -1512,12 +1529,14 @@ static void *thread_manage_apps(void *data)
        health_code_update();
 
        while (1) {
-               DBG("Apps thread polling on %d fds", LTTNG_POLL_GETNB(&events));
+               DBG("Apps thread polling");
 
                /* Inifinite blocking call, waiting for transmission */
        restart:
                health_poll_entry();
                ret = lttng_poll_wait(&events, -1);
+               DBG("Apps thread return from poll on %d fds",
+                               LTTNG_POLL_GETNB(&events));
                health_poll_exit();
                if (ret < 0) {
                        /*
@@ -1538,6 +1557,11 @@ static void *thread_manage_apps(void *data)
 
                        health_code_update();
 
+                       if (!revents) {
+                               /* No activity for this FD (poll implementation). */
+                               continue;
+                       }
+
                        /* Thread quit pipe has been closed. Killing thread. */
                        ret = sessiond_check_thread_quit_pipe(pollfd, revents);
                        if (ret) {
@@ -1716,6 +1740,11 @@ static void sanitize_wait_queue(struct ust_reg_wait_queue *wait_queue)
                uint32_t revents = LTTNG_POLL_GETEV(&events, i);
                int pollfd = LTTNG_POLL_GETFD(&events, i);
 
+               if (!revents) {
+                       /* No activity for this FD (poll implementation). */
+                       continue;
+               }
+
                cds_list_for_each_entry_safe(wait_node, tmp_wait_node,
                                &wait_queue->head, head) {
                        if (pollfd == wait_node->app->sock &&
@@ -2055,6 +2084,11 @@ static void *thread_registration_apps(void *data)
                        revents = LTTNG_POLL_GETEV(&events, i);
                        pollfd = LTTNG_POLL_GETFD(&events, i);
 
+                       if (!revents) {
+                               /* No activity for this FD (poll implementation). */
+                               continue;
+                       }
+
                        /* Thread quit pipe has been closed. Killing thread. */
                        ret = sessiond_check_thread_quit_pipe(pollfd, revents);
                        if (ret) {
@@ -3918,6 +3952,11 @@ restart:
                        revents = LTTNG_POLL_GETEV(&events, i);
                        pollfd = LTTNG_POLL_GETFD(&events, i);
 
+                       if (!revents) {
+                               /* No activity for this FD (poll implementation). */
+                               continue;
+                       }
+
                        /* Thread quit pipe has been closed. Killing thread. */
                        ret = sessiond_check_thread_quit_pipe(pollfd, revents);
                        if (ret) {
@@ -4090,6 +4129,11 @@ static void *thread_manage_clients(void *data)
 
                        health_code_update();
 
+                       if (!revents) {
+                               /* No activity for this FD (poll implementation). */
+                               continue;
+                       }
+
                        /* Thread quit pipe has been closed. Killing thread. */
                        ret = sessiond_check_thread_quit_pipe(pollfd, revents);
                        if (ret) {
@@ -4363,7 +4407,7 @@ static int set_option(int opt, const char *arg, const char *optname)
                }
                tracing_group_name = strdup(arg);
                if (!tracing_group_name) {
-                       perror("strdup");
+                       PERROR("strdup");
                        ret = -ENOMEM;
                }
                tracing_group_name_override = 1;
@@ -4427,7 +4471,7 @@ static int set_option(int opt, const char *arg, const char *optname)
                }
                consumerd32_bin = strdup(arg);
                if (!consumerd32_bin) {
-                       perror("strdup");
+                       PERROR("strdup");
                        ret = -ENOMEM;
                }
                consumerd32_bin_override = 1;
@@ -4438,7 +4482,7 @@ static int set_option(int opt, const char *arg, const char *optname)
                }
                consumerd32_libdir = strdup(arg);
                if (!consumerd32_libdir) {
-                       perror("strdup");
+                       PERROR("strdup");
                        ret = -ENOMEM;
                }
                consumerd32_libdir_override = 1;
@@ -4449,7 +4493,7 @@ static int set_option(int opt, const char *arg, const char *optname)
                }
                consumerd64_bin = strdup(arg);
                if (!consumerd64_bin) {
-                       perror("strdup");
+                       PERROR("strdup");
                        ret = -ENOMEM;
                }
                consumerd64_bin_override = 1;
@@ -4460,7 +4504,7 @@ static int set_option(int opt, const char *arg, const char *optname)
                }
                consumerd64_libdir = strdup(arg);
                if (!consumerd64_libdir) {
-                       perror("strdup");
+                       PERROR("strdup");
                        ret = -ENOMEM;
                }
                consumerd64_libdir_override = 1;
@@ -4469,7 +4513,7 @@ static int set_option(int opt, const char *arg, const char *optname)
                free(opt_pidfile);
                opt_pidfile = strdup(arg);
                if (!opt_pidfile) {
-                       perror("strdup");
+                       PERROR("strdup");
                        ret = -ENOMEM;
                }
                break;
@@ -4495,7 +4539,7 @@ static int set_option(int opt, const char *arg, const char *optname)
                free(opt_load_session_path);
                opt_load_session_path = strdup(arg);
                if (!opt_load_session_path) {
-                       perror("strdup");
+                       PERROR("strdup");
                        ret = -ENOMEM;
                }
                break;
@@ -4503,7 +4547,7 @@ static int set_option(int opt, const char *arg, const char *optname)
                free(kmod_probes_list);
                kmod_probes_list = strdup(arg);
                if (!kmod_probes_list) {
-                       perror("strdup");
+                       PERROR("strdup");
                        ret = -ENOMEM;
                }
                break;
@@ -4511,7 +4555,7 @@ static int set_option(int opt, const char *arg, const char *optname)
                free(kmod_extra_probes_list);
                kmod_extra_probes_list = strdup(arg);
                if (!kmod_extra_probes_list) {
-                       perror("strdup");
+                       PERROR("strdup");
                        ret = -ENOMEM;
                }
                break;
@@ -5165,6 +5209,12 @@ int main(int argc, char **argv)
                goto exit_ht_cleanup_pipe;
        }
 
+       /* Set up max poll set size */
+       if (lttng_poll_set_max_size()) {
+               retval = -1;
+               goto exit_set_max_size;
+       }
+
        /* Create thread to clean up RCU hash tables */
        ret = pthread_create(&ht_cleanup_thread, NULL,
                        thread_ht_cleanup, (void *) NULL);
@@ -5499,9 +5549,6 @@ int main(int argc, char **argv)
         */
        session_list_ptr = session_get_list();
 
-       /* Set up max poll set size */
-       lttng_poll_set_max_size();
-
        cmd_init();
 
        /* Check for the application socket timeout env variable. */
@@ -5731,6 +5778,7 @@ exit_init_data:
                retval = -1;
        }
 exit_ht_cleanup:
+exit_set_max_size:
 
        utils_close_pipe(ht_cleanup_pipe);
 exit_ht_cleanup_pipe:
This page took 0.028121 seconds and 4 git commands to generate.