#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/path.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 <common/logging-utils.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
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");
}
}
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);
* 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;
* 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);
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");
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;
* 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)) {
sessiond_config_log(&the_config);
sessiond_uuid_log();
+ lttng::logging::log_system_information(PRINT_DBG);
if (opt_print_version) {
print_version();
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;
}
if (!rotation_thread_handle) {
retval = -1;
ERR("Failed to create rotation thread shared data");
- stop_threads();
goto stop_threads;
}
* 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.
* 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();
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();