Fix: buffer overflow warning in python bindings
[lttng-tools.git] / src / bin / lttng-sessiond / main.c
index d9355b0199cc242d542e781d2ff1808d7b723afb..03f695ec672006e896b462c12aef673c8b861594 100644 (file)
@@ -1934,12 +1934,16 @@ static void *thread_dispatch_ust_registration(void *data)
 
        DBG("[thread] Dispatch UST command started");
 
-       while (!CMM_LOAD_SHARED(dispatch_thread_exit)) {
+       for (;;) {
                health_code_update();
 
                /* Atomically prepare the queue futex */
                futex_nto1_prepare(&ust_cmd_queue.futex);
 
+               if (CMM_LOAD_SHARED(dispatch_thread_exit)) {
+                       break;
+               }
+
                do {
                        struct ust_app *app = NULL;
                        ust_cmd = NULL;
@@ -2588,10 +2592,10 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
                        } else {
                                DBG("Could not find any valid consumerd executable");
                                ret = -EINVAL;
-                               break;
+                               goto error;
                        }
                        DBG("Using kernel consumer at: %s",  consumer_to_use);
-                       ret = execl(consumer_to_use,
+                       (void) execl(consumer_to_use,
                                "lttng-consumerd", verbosity, "-k",
                                "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path,
                                "--consumerd-err-sock", consumer_data->err_unix_sock_path,
@@ -2631,7 +2635,7 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
                                }
                        }
                        DBG("Using 64-bit UST consumer at: %s",  consumerd64_bin);
-                       ret = execl(consumerd64_bin, "lttng-consumerd", verbosity, "-u",
+                       (void) execl(consumerd64_bin, "lttng-consumerd", verbosity, "-u",
                                        "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path,
                                        "--consumerd-err-sock", consumer_data->err_unix_sock_path,
                                        "--group", tracing_group_name,
@@ -2674,7 +2678,7 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
                                }
                        }
                        DBG("Using 32-bit UST consumer at: %s",  consumerd32_bin);
-                       ret = execl(consumerd32_bin, "lttng-consumerd", verbosity, "-u",
+                       (void) execl(consumerd32_bin, "lttng-consumerd", verbosity, "-u",
                                        "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path,
                                        "--consumerd-err-sock", consumer_data->err_unix_sock_path,
                                        "--group", tracing_group_name,
@@ -2778,7 +2782,6 @@ static int init_kernel_tracer(void)
        kernel_tracer_fd = open(module_proc_lttng, O_RDWR);
        if (kernel_tracer_fd < 0) {
                DBG("Failed to open %s", module_proc_lttng);
-               ret = -1;
                goto error_open;
        }
 
@@ -2793,6 +2796,18 @@ static int init_kernel_tracer(void)
                goto error_modules;
        }
 
+       ret = kernel_supports_ring_buffer_snapshot_sample_positions(
+                       kernel_tracer_fd);
+       if (ret < 0) {
+               goto error_modules;
+       }
+
+       if (ret < 1) {
+               WARN("Kernel tracer does not support buffer monitoring. "
+                       "The monitoring timer of channels in the kernel domain "
+                       "will be set to 0 (disabled).");
+       }
+
        DBG("Kernel tracer fd %d", kernel_tracer_fd);
        return 0;
 
@@ -5392,13 +5407,10 @@ static int set_consumer_sockets(struct consumer_data *consumer_data,
        DBG2("Creating consumer directory: %s", path);
 
        ret = mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP);
-       if (ret < 0) {
-               if (errno != EEXIST) {
-                       PERROR("mkdir");
-                       ERR("Failed to create %s", path);
-                       goto error;
-               }
-               ret = -1;
+       if (ret < 0 && errno != EEXIST) {
+               PERROR("mkdir");
+               ERR("Failed to create %s", path);
+               goto error;
        }
        if (is_root) {
                ret = chown(path, 0, utils_get_group_id(tracing_group_name));
@@ -5618,6 +5630,7 @@ int main(int argc, char **argv)
        struct lttng_pipe *ust32_channel_monitor_pipe = NULL,
                        *ust64_channel_monitor_pipe = NULL,
                        *kernel_channel_monitor_pipe = NULL;
+       bool notification_thread_running = false;
 
        init_kernel_workarounds();
 
@@ -6129,6 +6142,7 @@ int main(int argc, char **argv)
                stop_threads();
                goto exit_notification;
        }
+       notification_thread_running = true;
 
        /* Create thread to manage the client socket */
        ret = pthread_create(&client_thread, default_pthread_attr(),
@@ -6332,17 +6346,19 @@ exit_init_data:
         * of the active session and channels at the moment of the teardown.
         */
        if (notification_thread_handle) {
-               notification_thread_command_quit(notification_thread_handle);
+               if (notification_thread_running) {
+                       notification_thread_command_quit(
+                                       notification_thread_handle);
+                       ret = pthread_join(notification_thread, &status);
+                       if (ret) {
+                               errno = ret;
+                               PERROR("pthread_join notification thread");
+                               retval = -1;
+                       }
+               }
                notification_thread_handle_destroy(notification_thread_handle);
        }
 
-       ret = pthread_join(notification_thread, &status);
-       if (ret) {
-               errno = ret;
-               PERROR("pthread_join notification thread");
-               retval = -1;
-       }
-
        rcu_thread_offline();
        rcu_unregister_thread();
 
This page took 0.025284 seconds and 4 git commands to generate.