Fix: put session list lock around the app registration
[lttng-tools.git] / src / bin / lttng-sessiond / main.c
index 034621e9da466ca1b4c49d0a7e4875f515e7fdaf..d95cfa9bbcd6b837633a0bfea5151ccf44451d53 100644 (file)
@@ -658,8 +658,6 @@ static void update_ust_app(int app_sock)
 {
        struct ltt_session *sess, *stmp;
 
-       session_lock_list();
-
        /* For all tracing session(s) */
        cds_list_for_each_entry_safe(sess, stmp, &session_list_ptr->head, list) {
                session_lock(sess);
@@ -668,8 +666,6 @@ static void update_ust_app(int app_sock)
                }
                session_unlock(sess);
        }
-
-       session_unlock_list();
 }
 
 /*
@@ -734,9 +730,9 @@ static void *thread_manage_kernel(void *data)
 
                /* Poll infinite value of time */
        restart:
-               health_poll_update();
+               health_poll_entry();
                ret = lttng_poll_wait(&events, -1);
-               health_poll_update();
+               health_poll_exit();
                if (ret < 0) {
                        /*
                         * Restart interrupted system call.
@@ -855,24 +851,7 @@ static void *thread_manage_consumer(void *data)
 
        health_register(HEALTH_TYPE_CONSUMER);
 
-       /*
-        * Since the consumer thread can be spawned at any moment in time, we init
-        * the health to a poll status (1, which is a valid health over time).
-        * When the thread starts, we update here the health to a "code" path being
-        * an even value so this thread, when reaching a poll wait, does not
-        * trigger an error with an even value.
-        *
-        * Here is the use case we avoid.
-        *
-        * +1: the first poll update during initialization (main())
-        * +2 * x: multiple code update once in this thread.
-        * +1: poll wait in this thread (being a good health state).
-        * == even number which after the wait period shows as a bad health.
-        *
-        * In a nutshell, the following poll update to the health state brings back
-        * the state to an even value meaning a code path.
-        */
-       health_poll_update();
+       health_code_update();
 
        /*
         * Pass 2 as size here for the thread quit pipe and kconsumerd_err_sock.
@@ -897,14 +876,14 @@ static void *thread_manage_consumer(void *data)
 
        /* Inifinite blocking call, waiting for transmission */
 restart:
-       health_poll_update();
+       health_poll_entry();
 
        if (testpoint(thread_manage_consumer)) {
                goto error;
        }
 
        ret = lttng_poll_wait(&events, -1);
-       health_poll_update();
+       health_poll_exit();
        if (ret < 0) {
                /*
                 * Restart interrupted system call.
@@ -996,9 +975,9 @@ restart:
 
        /* Inifinite blocking call, waiting for transmission */
 restart_poll:
-       health_poll_update();
+       health_poll_entry();
        ret = lttng_poll_wait(&events, -1);
-       health_poll_update();
+       health_poll_exit();
        if (ret < 0) {
                /*
                 * Restart interrupted system call.
@@ -1138,9 +1117,9 @@ static void *thread_manage_apps(void *data)
 
                /* Inifinite blocking call, waiting for transmission */
        restart:
-               health_poll_update();
+               health_poll_entry();
                ret = lttng_poll_wait(&events, -1);
-               health_poll_update();
+               health_poll_exit();
                if (ret < 0) {
                        /*
                         * Restart interrupted system call.
@@ -1184,12 +1163,22 @@ static void *thread_manage_apps(void *data)
 
                                        health_code_update();
 
+                                       /*
+                                        * @session_lock
+                                        * Lock the global session list so from the register up to
+                                        * the registration done message, no thread can see the
+                                        * application and change its state.
+                                        */
+                                       session_lock_list();
+
                                        /* Register applicaton to the session daemon */
                                        ret = ust_app_register(&ust_cmd.reg_msg,
                                                        ust_cmd.sock);
                                        if (ret == -ENOMEM) {
+                                               session_unlock_list();
                                                goto error;
                                        } else if (ret < 0) {
+                                               session_unlock_list();
                                                break;
                                        }
 
@@ -1225,6 +1214,7 @@ static void *thread_manage_apps(void *data)
                                                ret = lttng_poll_add(&events, ust_cmd.sock,
                                                                LPOLLERR & LPOLLHUP & LPOLLRDHUP);
                                                if (ret < 0) {
+                                                       session_unlock_list();
                                                        goto error;
                                                }
 
@@ -1237,6 +1227,7 @@ static void *thread_manage_apps(void *data)
                                                DBG("Apps with sock %d added to poll set",
                                                                ust_cmd.sock);
                                        }
+                                       session_unlock_list();
 
                                        health_code_update();
 
@@ -1418,9 +1409,9 @@ static void *thread_registration_apps(void *data)
 
                /* Inifinite blocking call, waiting for transmission */
        restart:
-               health_poll_update();
+               health_poll_entry();
                ret = lttng_poll_wait(&events, -1);
-               health_poll_update();
+               health_poll_exit();
                if (ret < 0) {
                        /*
                         * Restart interrupted system call.
@@ -3196,9 +3187,9 @@ static void *thread_manage_clients(void *data)
 
                /* Inifinite blocking call, waiting for transmission */
        restart:
-               health_poll_update();
+               health_poll_entry();
                ret = lttng_poll_wait(&events, -1);
-               health_poll_update();
+               health_poll_exit();
                if (ret < 0) {
                        /*
                         * Restart interrupted system call.
This page took 0.026083 seconds and 4 git commands to generate.