Fix: free running directory string
[lttng-tools.git] / src / bin / lttng-sessiond / main.c
index 85a20d795cb253123c0b2753a02a8fcad98e8436..0e20b4f67886dc656e88e5631cce8fc223379205 100644 (file)
@@ -61,6 +61,7 @@
 #include "fd-limit.h"
 #include "filter.h"
 #include "health.h"
+#include "testpoint.h"
 
 #define CONSUMERD_FILE "lttng-consumerd"
 
@@ -688,8 +689,12 @@ static void *thread_manage_kernel(void *data)
 
        DBG("Thread manage kernel started");
 
+       testpoint(thread_manage_kernel);
+
        health_code_update(&health_thread_kernel);
 
+       testpoint(thread_manage_kernel_before_loop);
+
        ret = create_thread_poll_set(&events, 2);
        if (ret < 0) {
                goto error_poll_create;
@@ -860,6 +865,9 @@ static void *thread_manage_consumer(void *data)
        /* Inifinite blocking call, waiting for transmission */
 restart:
        health_poll_update(&consumer_data->health);
+
+       testpoint(thread_manage_consumer);
+
        ret = lttng_poll_wait(&events, -1);
        health_poll_update(&consumer_data->health);
        if (ret < 0) {
@@ -1057,6 +1065,8 @@ static void *thread_manage_apps(void *data)
 
        DBG("[thread] Manage application started");
 
+       testpoint(thread_manage_apps);
+
        rcu_register_thread();
        rcu_thread_online();
 
@@ -1072,6 +1082,8 @@ static void *thread_manage_apps(void *data)
                goto error;
        }
 
+       testpoint(thread_manage_apps_before_loop);
+
        health_code_update(&health_thread_app_manage);
 
        while (1) {
@@ -1295,6 +1307,8 @@ static void *thread_registration_apps(void *data)
 
        DBG("[thread] Manage application registration started");
 
+       testpoint(thread_registration_apps);
+
        ret = lttcomm_listen_unix_sock(apps_sock);
        if (ret < 0) {
                goto error_listen;
@@ -1912,6 +1926,15 @@ static int copy_session_consumer(int domain, struct ltt_session *session)
        switch (domain) {
        case LTTNG_DOMAIN_KERNEL:
                DBG3("Copying tracing session consumer output in kernel session");
+               /*
+                * XXX: We should audit the session creation and what this function
+                * does "extra" in order to avoid a destroy since this function is used
+                * in the domain session creation (kernel and ust) only. Same for UST
+                * domain.
+                */
+               if (session->kernel_session->consumer) {
+                       consumer_destroy_output(session->kernel_session->consumer);
+               }
                session->kernel_session->consumer =
                        consumer_copy_output(session->consumer);
                /* Ease our life a bit for the next part */
@@ -1920,6 +1943,9 @@ static int copy_session_consumer(int domain, struct ltt_session *session)
                break;
        case LTTNG_DOMAIN_UST:
                DBG3("Copying tracing session consumer output in UST session");
+               if (session->ust_session->consumer) {
+                       consumer_destroy_output(session->ust_session->consumer);
+               }
                session->ust_session->consumer =
                        consumer_copy_output(session->consumer);
                /* Ease our life a bit for the next part */
@@ -2088,6 +2114,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock,
        case LTTNG_LIST_DOMAINS:
        case LTTNG_START_TRACE:
        case LTTNG_STOP_TRACE:
+       case LTTNG_DATA_AVAILABLE:
                need_domain = 0;
                break;
        default:
@@ -2526,12 +2553,14 @@ skip_domain:
                        DBG("No URIs received from client... continuing");
                        *sock_error = 1;
                        ret = LTTNG_ERR_SESSION_FAIL;
+                       free(uris);
                        goto error;
                }
 
                ret = cmd_set_consumer_uri(cmd_ctx->lsm->domain.type, cmd_ctx->session,
                                nb_uri, uris);
                if (ret != LTTNG_OK) {
+                       free(uris);
                        goto error;
                }
 
@@ -2552,6 +2581,8 @@ skip_domain:
                        }
                }
 
+               free(uris);
+
                break;
        }
        case LTTNG_START_TRACE:
@@ -2586,12 +2617,14 @@ skip_domain:
                                DBG("No URIs received from client... continuing");
                                *sock_error = 1;
                                ret = LTTNG_ERR_SESSION_FAIL;
+                               free(uris);
                                goto error;
                        }
 
                        if (nb_uri == 1 && uris[0].dtype != LTTNG_DST_PATH) {
                                DBG("Creating session with ONE network URI is a bad call");
                                ret = LTTNG_ERR_SESSION_FAIL;
+                               free(uris);
                                goto error;
                        }
                }
@@ -2599,6 +2632,8 @@ skip_domain:
                ret = cmd_create_session_uri(cmd_ctx->lsm->session.name, uris, nb_uri,
                        &cmd_ctx->creds);
 
+               free(uris);
+
                break;
        }
        case LTTNG_DESTROY_SESSION:
@@ -2774,6 +2809,11 @@ skip_domain:
                                bytecode);
                break;
        }
+       case LTTNG_DATA_AVAILABLE:
+       {
+               ret = cmd_data_available(cmd_ctx->session);
+               break;
+       }
        default:
                ret = LTTNG_ERR_UND;
                break;
@@ -2994,6 +3034,8 @@ static void *thread_manage_clients(void *data)
 
        DBG("[thread] Manage client started");
 
+       testpoint(thread_manage_clients);
+
        rcu_register_thread();
 
        health_code_update(&health_thread_cmd);
@@ -3025,6 +3067,8 @@ static void *thread_manage_clients(void *data)
                kill(ppid, SIGUSR1);
        }
 
+       testpoint(thread_manage_clients_before_loop);
+
        health_code_update(&health_thread_cmd);
 
        while (1) {
@@ -3941,6 +3985,9 @@ int main(int argc, char **argv)
        health_init(&ustconsumer64_data.health);
        health_poll_update(&ustconsumer64_data.health);
 
+       /* Not needed anymore. */
+       free(rundir);
+
        /* Create thread to manage the client socket */
        ret = pthread_create(&health_thread, NULL,
                        thread_manage_health, (void *) NULL);
This page took 0.025648 seconds and 4 git commands to generate.