Cleanup: sessiond: rename the sessiond main thread quit pipe
[lttng-tools.git] / src / bin / lttng-sessiond / main.cpp
index a676b257fc818b8b8dea711731ad3d7b2ac2e23f..23136f7c8deab6aa4677d51b9b40908b0c76edfd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 EfficiOS Inc.
  * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
 #include <unistd.h>
 #include <ctype.h>
 
-#include <common/common.h>
-#include <common/compat/socket.h>
-#include <common/compat/getenv.h>
-#include <common/defaults.h>
-#include <common/kernel-consumer/kernel-consumer.h>
-#include <common/futex.h>
-#include <common/relayd/relayd.h>
-#include <common/utils.h>
-#include <common/daemonize.h>
-#include <common/config/session-config.h>
-#include <common/ini-config/ini-config.h>
-#include <common/dynamic-buffer.h>
-#include <lttng/event-internal.h>
-
-#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 "ht-cleanup.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 <common/common.hpp>
+#include <common/compat/socket.hpp>
+#include <common/compat/getenv.hpp>
+#include <common/defaults.hpp>
+#include <common/kernel-consumer/kernel-consumer.hpp>
+#include <common/futex.hpp>
+#include <common/relayd/relayd.hpp>
+#include <common/utils.hpp>
+#include <common/path.hpp>
+#include <common/daemonize.hpp>
+#include <common/config/session-config.hpp>
+#include <common/ini-config/ini-config.hpp>
+#include <common/dynamic-buffer.hpp>
+#include <lttng/event-internal.hpp>
+#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");
@@ -1447,7 +1452,6 @@ int main(int argc, char **argv)
        struct lttng_pipe *ust32_channel_monitor_pipe = NULL,
                        *ust64_channel_monitor_pipe = NULL,
                        *kernel_channel_monitor_pipe = NULL;
-       struct lttng_thread *ht_cleanup_thread = NULL;
        struct timer_thread_parameters timer_thread_parameters;
        /* Rotation thread handle. */
        struct rotation_thread_handle *rotation_thread_handle = NULL;
@@ -1496,9 +1500,7 @@ int main(int argc, char **argv)
         * Parse arguments and load the daemon configuration file.
         *
         * We have an exit_options exit path to free memory reserved by
-        * set_options. This is needed because the rest of sessiond_cleanup()
-        * depends on ht_cleanup_thread, which depends on lttng_daemonize, which
-        * depends on set_options.
+        * set_options.
         */
        progname = argv[0];
        if (set_options(argc, argv)) {
@@ -1599,15 +1601,8 @@ int main(int argc, char **argv)
                goto stop_threads;
        }
 
-       /* Create thread to clean up RCU hash tables */
-       ht_cleanup_thread = launch_ht_cleanup_thread();
-       if (!ht_cleanup_thread) {
-               retval = -1;
-               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;
        }
@@ -1832,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;
        }
 
@@ -1925,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.
@@ -1960,10 +1956,7 @@ stop_threads:
         * perform lookups in those structures.
         */
        rcu_barrier();
-       /*
-        * sessiond_cleanup() is called when no other thread is running, except
-        * the ht_cleanup thread, which is needed to destroy the hash tables.
-        */
+
        rcu_thread_online();
        sessiond_cleanup();
 
@@ -2000,18 +1993,6 @@ stop_threads:
                modprobe_remove_lttng_all();
        }
 
-       /*
-        * Ensure all prior call_rcu are done. call_rcu callbacks may push
-        * hash tables to the ht_cleanup thread. Therefore, we ensure that
-        * the queue is empty before shutting down the clean-up thread.
-        */
-       rcu_barrier();
-
-       if (ht_cleanup_thread) {
-               lttng_thread_shutdown(ht_cleanup_thread);
-               lttng_thread_put(ht_cleanup_thread);
-       }
-
        rcu_thread_offline();
        rcu_unregister_thread();
 
This page took 0.028194 seconds and 4 git commands to generate.