X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fmain.c;h=c82e0095bc1e476b015a164a61975a661d39ff95;hb=a5ab9e05759b9c61c40c845c1ec0e794307f0569;hp=8820fdbddca9ee8e177063c290be0f917e92ea72;hpb=225221a8932cba30dda6c05b3722f700396f0a9c;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 8820fdbdd..c82e0095b 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -194,9 +194,6 @@ static pthread_t kernel_thread; static pthread_t dispatch_thread; static pthread_t agent_reg_thread; static pthread_t load_session_thread; -static pthread_t notification_thread; -static pthread_t rotation_thread; -static pthread_t timer_thread; /* * UST registration command queue. This queue is tied with a futex and uses a N @@ -256,9 +253,6 @@ static const char * const config_section_name = "sessiond"; /* Am I root or not. Set to 1 if the daemon is running as root */ static int is_root; -/* Rotation thread handle. */ -static struct rotation_thread_handle *rotation_thread_handle; - /* * Stop all threads by closing the thread quit pipe. */ @@ -5497,14 +5491,12 @@ 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_launched = false; - bool rotation_thread_launched = false; - bool timer_thread_launched = false; struct lttng_thread *ht_cleanup_thread = NULL; - struct timer_thread_parameters timer_thread_ctx; + struct timer_thread_parameters timer_thread_parameters; + /* Rotation thread handle. */ + struct rotation_thread_handle *rotation_thread_handle = NULL; /* Queue of rotation jobs populated by the sessiond-timer. */ struct rotation_thread_timer_queue *rotation_timer_queue = NULL; - sem_t notification_thread_ready; init_kernel_workarounds(); @@ -5699,7 +5691,8 @@ int main(int argc, char **argv) retval = -1; goto exit_init_data; } - timer_thread_ctx.rotation_thread_job_queue = rotation_timer_queue; + timer_thread_parameters.rotation_thread_job_queue = + rotation_timer_queue; ust64_channel_monitor_pipe = lttng_pipe_open(0); if (!ust64_channel_monitor_pipe) { @@ -5853,55 +5846,33 @@ int main(int argc, char **argv) goto exit_health; } - /* - * The rotation thread needs the notification thread to be ready before - * creating the rotate_notification_channel, so we use this semaphore as - * a rendez-vous point. - */ - sem_init(¬ification_thread_ready, 0, 0); - /* notification_thread_data acquires the pipes' read side. */ notification_thread_handle = notification_thread_handle_create( ust32_channel_monitor_pipe, ust64_channel_monitor_pipe, - kernel_channel_monitor_pipe, - ¬ification_thread_ready); + kernel_channel_monitor_pipe); if (!notification_thread_handle) { retval = -1; ERR("Failed to create notification thread shared data"); - stop_threads(); goto exit_notification; } /* Create notification thread. */ - ret = pthread_create(¬ification_thread, default_pthread_attr(), - thread_notification, notification_thread_handle); - if (ret) { - errno = ret; - PERROR("pthread_create notification"); + if (!launch_notification_thread(notification_thread_handle)) { retval = -1; - stop_threads(); goto exit_notification; } - notification_thread_launched = true; /* Create timer thread. */ - ret = pthread_create(&timer_thread, default_pthread_attr(), - timer_thread_func, &timer_thread_ctx); - if (ret) { - errno = ret; - PERROR("pthread_create timer"); + if (!launch_timer_thread(&timer_thread_parameters)) { retval = -1; - stop_threads(); goto exit_notification; } - timer_thread_launched = true; /* rotation_thread_data acquires the pipes' read side. */ rotation_thread_handle = rotation_thread_handle_create( rotation_timer_queue, - notification_thread_handle, - ¬ification_thread_ready); + notification_thread_handle); if (!rotation_thread_handle) { retval = -1; ERR("Failed to create rotation thread shared data"); @@ -5910,16 +5881,10 @@ int main(int argc, char **argv) } /* Create rotation thread. */ - ret = pthread_create(&rotation_thread, default_pthread_attr(), - thread_rotation, rotation_thread_handle); - if (ret) { - errno = ret; - PERROR("pthread_create rotation"); + if (!launch_rotation_thread(rotation_thread_handle)) { retval = -1; - stop_threads(); goto exit_rotation; } - rotation_thread_launched = true; /* Create thread to manage the client socket */ ret = pthread_create(&client_thread, default_pthread_attr(), @@ -6093,7 +6058,6 @@ exit_dispatch: exit_client: exit_rotation: exit_notification: - sem_destroy(¬ification_thread_ready); lttng_thread_list_shutdown_orphans(); exit_health: exit_init_data: @@ -6117,61 +6081,31 @@ exit_init_data: */ rcu_barrier(); - /* - * The teardown of the notification system is performed after the - * session daemon's teardown in order to allow it to be notified - * of the active session and channels at the moment of the teardown. - */ - if (notification_thread_handle) { - if (notification_thread_launched) { - 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); + if (ht_cleanup_thread) { + lttng_thread_shutdown(ht_cleanup_thread); + lttng_thread_put(ht_cleanup_thread); } + rcu_thread_offline(); + rcu_unregister_thread(); + if (rotation_thread_handle) { - if (rotation_thread_launched) { - ret = pthread_join(rotation_thread, &status); - if (ret) { - errno = ret; - PERROR("pthread_join rotation thread"); - retval = -1; - } - } rotation_thread_handle_destroy(rotation_thread_handle); } - if (timer_thread_launched) { - timer_exit(); - ret = pthread_join(timer_thread, &status); - if (ret) { - errno = ret; - PERROR("pthread_join timer thread"); - retval = -1; - } - } - - if (ht_cleanup_thread) { - lttng_thread_shutdown(ht_cleanup_thread); - lttng_thread_put(ht_cleanup_thread); - } - /* * After the rotation and timer thread have quit, we can safely destroy * the rotation_timer_queue. */ rotation_thread_timer_queue_destroy(rotation_timer_queue); - - rcu_thread_offline(); - rcu_unregister_thread(); - + /* + * The teardown of the notification system is performed after the + * session daemon's teardown in order to allow it to be notified + * of the active session and channels at the moment of the teardown. + */ + if (notification_thread_handle) { + notification_thread_handle_destroy(notification_thread_handle); + } lttng_pipe_destroy(ust32_channel_monitor_pipe); lttng_pipe_destroy(ust64_channel_monitor_pipe); lttng_pipe_destroy(kernel_channel_monitor_pipe);