X-Git-Url: https://git.liburcu.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fmain.cpp;h=23136f7c8deab6aa4677d51b9b40908b0c76edfd;hp=d8d2caf8b2c9c387d4762b03d0968790584e0199;hb=f90a04edabf22fccd0ac546bf04d7d7a795e3b92;hpb=3c3390532736cfb5198f863d0d2b218e21fcf76d diff --git a/src/bin/lttng-sessiond/main.cpp b/src/bin/lttng-sessiond/main.cpp index d8d2caf8b..23136f7c8 100644 --- a/src/bin/lttng-sessiond/main.cpp +++ b/src/bin/lttng-sessiond/main.cpp @@ -29,54 +29,53 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "lttng-sessiond.h" -#include "buffer-registry.h" -#include "channel.h" -#include "cmd.h" -#include "consumer.h" -#include "context.h" -#include "event.h" -#include "event-notifier-error-accounting.h" -#include "kernel.h" -#include "kernel-consumer.h" -#include "lttng-ust-ctl.h" -#include "ust-consumer.h" -#include "utils.h" -#include "fd-limit.h" -#include "health-sessiond.h" -#include "testpoint.h" -#include "notify-apps.h" -#include "agent-thread.h" -#include "save.h" -#include "notification-thread.h" -#include "notification-thread-commands.h" -#include "rotation-thread.h" -#include "agent.h" -#include "sessiond-config.h" -#include "timer.h" -#include "thread.h" -#include "client.h" -#include "dispatch.h" -#include "register.h" -#include "manage-apps.h" -#include "manage-kernel.h" -#include "modprobe.h" -#include "ust-sigbus.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "lttng-sessiond.hpp" +#include "buffer-registry.hpp" +#include "channel.hpp" +#include "cmd.hpp" +#include "consumer.hpp" +#include "context.hpp" +#include "event.hpp" +#include "event-notifier-error-accounting.hpp" +#include "kernel.hpp" +#include "kernel-consumer.hpp" +#include "lttng-ust-ctl.hpp" +#include "ust-consumer.hpp" +#include "utils.hpp" +#include "fd-limit.hpp" +#include "health-sessiond.hpp" +#include "testpoint.hpp" +#include "notify-apps.hpp" +#include "agent-thread.hpp" +#include "save.hpp" +#include "notification-thread.hpp" +#include "notification-thread-commands.hpp" +#include "rotation-thread.hpp" +#include "agent.hpp" +#include "sessiond-config.hpp" +#include "timer.hpp" +#include "thread.hpp" +#include "client.hpp" +#include "dispatch.hpp" +#include "register.hpp" +#include "manage-apps.hpp" +#include "manage-kernel.hpp" +#include "modprobe.hpp" +#include "ust-sigbus.hpp" static const char *help_msg = #ifdef LTTNG_EMBED_HELP @@ -167,17 +166,18 @@ static const char * const config_section_name = "sessiond"; static int is_root; /* - * Stop all threads by closing the thread quit pipe. + * Notify the main thread to initiate the teardown of the worker threads by + * writing to the main quit pipe. */ -static void stop_threads(void) +static void notify_main_quit_pipe(void) { int ret; /* Stopping all threads */ - DBG("Terminating all threads"); - ret = sessiond_notify_quit_pipe(); + DBG("Notify the main thread to terminate all worker threads"); + ret = sessiond_notify_main_quit_pipe(); if (ret < 0) { - ERR("write error on thread quit pipe"); + ERR("write error on main quit pipe"); } } @@ -282,10 +282,12 @@ static void sessiond_cleanup(void) DBG("Cleanup sessiond"); /* - * Close the thread quit pipe. It has already done its job, - * since we are now called. + * Close the main quit pipe. It has already done its job, since we are + * now cleaning up. */ - sessiond_close_quit_pipe(); + sessiond_close_main_quit_pipe(); + + /* Close all other pipes. */ utils_close_pipe(apps_cmd_pipe); utils_close_pipe(apps_cmd_notify_pipe); utils_close_pipe(the_kernel_poll_pipe); @@ -795,7 +797,8 @@ end: * See config_entry_handler_cb comment in common/config/session-config.h for the * return value conventions. */ -static int config_entry_handler(const struct config_entry *entry, void *unused) +static int config_entry_handler(const struct config_entry *entry, + void *unused __attribute__((unused))) { int ret = 0, i; @@ -1172,16 +1175,17 @@ error: * Simply stop all worker threads, leaving main() return gracefully after * joining all threads and calling cleanup(). */ -static void sighandler(int sig, siginfo_t *siginfo, void *arg) +static void sighandler(int sig, siginfo_t *siginfo, + void *arg __attribute__((unused))) { switch (sig) { case SIGINT: DBG("SIGINT caught"); - stop_threads(); + notify_main_quit_pipe(); break; case SIGTERM: DBG("SIGTERM caught"); - stop_threads(); + notify_main_quit_pipe(); break; case SIGUSR1: CMM_STORE_SHARED(recv_child_signal, 1); @@ -1359,6 +1363,7 @@ static void unregister_all_triggers(void) unsigned int trigger_count, i; const struct lttng_credentials creds = { .uid = LTTNG_OPTIONAL_INIT_VALUE(0), + .gid = LTTNG_OPTIONAL_INIT_UNSET, }; DBG("Unregistering all triggers"); @@ -1596,8 +1601,8 @@ int main(int argc, char **argv) goto stop_threads; } - /* Create thread quit pipe */ - if (sessiond_init_thread_quit_pipe()) { + /* Create main quit pipe */ + if (sessiond_init_main_quit_pipe()) { retval = -1; goto stop_threads; } @@ -1822,7 +1827,6 @@ int main(int argc, char **argv) if (!rotation_thread_handle) { retval = -1; ERR("Failed to create rotation thread shared data"); - stop_threads(); goto stop_threads; } @@ -1915,11 +1919,13 @@ int main(int argc, char **argv) * signal that asks threads to teardown). */ - /* Initiate teardown once activity occurs on the quit pipe. */ - sessiond_wait_for_quit_pipe(-1); + /* Initiate teardown once activity occurs on the main quit pipe. */ + sessiond_wait_for_main_quit_pipe(-1); stop_threads: + DBG("Terminating all threads"); + /* * Ensure that the client thread is no longer accepting new commands, * which could cause new sessions to be created.