Use compiler-agnostic defines to silence warning
[lttng-tools.git] / src / bin / lttng-sessiond / main.cpp
index 01633390522d6ecec7f2c265155663d48fcd7ea9..0902969e71dee38b7319e007329e823e785afdc6 100644 (file)
@@ -52,6 +52,7 @@
 #include <common/futex.hpp>
 #include <common/ini-config/ini-config.hpp>
 #include <common/kernel-consumer/kernel-consumer.hpp>
 #include <common/futex.hpp>
 #include <common/ini-config/ini-config.hpp>
 #include <common/kernel-consumer/kernel-consumer.hpp>
+#include <common/lockfile.hpp>
 #include <common/logging-utils.hpp>
 #include <common/path.hpp>
 #include <common/relayd/relayd.hpp>
 #include <common/logging-utils.hpp>
 #include <common/path.hpp>
 #include <common/relayd/relayd.hpp>
@@ -276,7 +277,6 @@ static void wait_consumer(struct consumer_data *consumer_data)
 static void sessiond_cleanup()
 {
        int ret;
 static void sessiond_cleanup()
 {
        int ret;
-       struct ltt_session_list *session_list = session_get_list();
 
        DBG("Cleanup sessiond");
 
 
        DBG("Cleanup sessiond");
 
@@ -326,8 +326,6 @@ static void sessiond_cleanup()
        DBG("Removing directory %s", the_config.consumerd64_path.value);
        (void) rmdir(the_config.consumerd64_path.value);
 
        DBG("Removing directory %s", the_config.consumerd64_path.value);
        (void) rmdir(the_config.consumerd64_path.value);
 
-       pthread_mutex_destroy(&session_list->lock);
-
        DBG("Cleaning up all per-event notifier domain agents");
        agent_by_event_notifier_domain_ht_destroy();
 
        DBG("Cleaning up all per-event notifier domain agents");
        agent_by_event_notifier_domain_ht_destroy();
 
@@ -791,7 +789,7 @@ static int config_entry_handler(const struct config_entry *entry,
 
        for (i = 0; i < (sizeof(long_options) / sizeof(struct option)) - 1; i++) {
                /* Ignore if not fully matched. */
 
        for (i = 0; i < (sizeof(long_options) / sizeof(struct option)) - 1; i++) {
                /* Ignore if not fully matched. */
-               if (strcmp(entry->name, long_options[i].name)) {
+               if (strcmp(entry->name, long_options[i].name) != 0) {
                        continue;
                }
 
                        continue;
                }
 
@@ -1281,38 +1279,38 @@ end:
 
 static void destroy_all_sessions_and_wait()
 {
 
 static void destroy_all_sessions_and_wait()
 {
-       struct ltt_session *session, *tmp;
        struct ltt_session_list *session_list;
 
        struct ltt_session_list *session_list;
 
-       session_list = session_get_list();
        DBG("Initiating destruction of all sessions");
 
        DBG("Initiating destruction of all sessions");
 
+       auto list_lock = lttng::sessiond::lock_session_list();
+
+       session_list = session_get_list();
        if (!session_list) {
                return;
        }
 
        if (!session_list) {
                return;
        }
 
-       session_lock_list();
        /* Initiate the destruction of all sessions. */
        /* Initiate the destruction of all sessions. */
-       cds_list_for_each_entry_safe (session, tmp, &session_list->head, list) {
-               if (!session_get(session)) {
-                       continue;
-               }
+       for (auto raw_session_ptr :
+            lttng::urcu::list_iteration_adapter<ltt_session, &ltt_session::list>(
+                    session_list->head)) {
+               const auto session = [raw_session_ptr]() {
+                       session_get(raw_session_ptr);
+                       raw_session_ptr->lock();
+                       return ltt_session::make_locked_ref(*raw_session_ptr);
+               }();
 
 
-               session_lock(session);
                if (session->destroyed) {
                if (session->destroyed) {
-                       goto unlock_session;
+                       continue;
                }
                }
+
                (void) cmd_stop_trace(session);
                (void) cmd_stop_trace(session);
-               (void) cmd_destroy_session(session, the_notification_thread_handle, nullptr);
-       unlock_session:
-               session_unlock(session);
-               session_put(session);
+               (void) cmd_destroy_session(session, nullptr);
        }
        }
-       session_unlock_list();
 
        /* Wait for the destruction of all sessions to complete. */
        DBG("Waiting for the destruction of all sessions to complete");
 
        /* Wait for the destruction of all sessions to complete. */
        DBG("Waiting for the destruction of all sessions to complete");
-       session_list_wait_empty();
+       session_list_wait_empty(std::move(list_lock));
        DBG("Destruction of all sessions completed");
 }
 
        DBG("Destruction of all sessions completed");
 }
 
@@ -1403,7 +1401,7 @@ static void sessiond_uuid_log()
 /*
  * main
  */
 /*
  * main
  */
-int main(int argc, char **argv)
+static int _main(int argc, char **argv)
 {
        int ret = 0, retval = 0;
        const char *env_app_timeout;
 {
        int ret = 0, retval = 0;
        const char *env_app_timeout;
@@ -1411,10 +1409,8 @@ int main(int argc, char **argv)
                          *ust64_channel_monitor_pipe = nullptr,
                          *kernel_channel_monitor_pipe = nullptr;
        struct timer_thread_parameters timer_thread_parameters;
                          *ust64_channel_monitor_pipe = nullptr,
                          *kernel_channel_monitor_pipe = nullptr;
        struct timer_thread_parameters timer_thread_parameters;
-       /* Rotation thread handle. */
-       struct rotation_thread_handle *rotation_thread_handle = nullptr;
        /* Queue of rotation jobs populated by the sessiond-timer. */
        /* Queue of rotation jobs populated by the sessiond-timer. */
-       struct rotation_thread_timer_queue *rotation_timer_queue = nullptr;
+       lttng::sessiond::rotation_thread_timer_queue *rotation_timer_queue = nullptr;
        struct lttng_thread *client_thread = nullptr;
        struct lttng_thread *notification_thread = nullptr;
        struct lttng_thread *register_apps_thread = nullptr;
        struct lttng_thread *client_thread = nullptr;
        struct lttng_thread *notification_thread = nullptr;
        struct lttng_thread *register_apps_thread = nullptr;
@@ -1600,7 +1596,7 @@ int main(int argc, char **argv)
         * sessiond timer thread and the rotation thread. The main thread keeps
         * its ownership and destroys it when both threads have been joined.
         */
         * sessiond timer thread and the rotation thread. The main thread keeps
         * its ownership and destroys it when both threads have been joined.
         */
-       rotation_timer_queue = rotation_thread_timer_queue_create();
+       rotation_timer_queue = lttng::sessiond::rotation_thread_timer_queue_create();
        if (!rotation_timer_queue) {
                retval = -1;
                goto stop_threads;
        if (!rotation_timer_queue) {
                retval = -1;
                goto stop_threads;
@@ -1771,18 +1767,20 @@ int main(int argc, char **argv)
                goto stop_threads;
        }
 
                goto stop_threads;
        }
 
-       /* rotation_thread_data acquires the pipes' read side. */
-       rotation_thread_handle =
-               rotation_thread_handle_create(rotation_timer_queue, the_notification_thread_handle);
-       if (!rotation_thread_handle) {
+       try {
+               the_rotation_thread_handle = lttng::make_unique<lttng::sessiond::rotation_thread>(
+                       *rotation_timer_queue, *the_notification_thread_handle);
+       } catch (const std::exception& e) {
                retval = -1;
                retval = -1;
-               ERR("Failed to create rotation thread shared data");
+               ERR("Failed to create rotation thread: %s", e.what());
                goto stop_threads;
        }
 
                goto stop_threads;
        }
 
-       /* Create rotation thread. */
-       if (!launch_rotation_thread(rotation_thread_handle)) {
+       try {
+               the_rotation_thread_handle->launch_thread();
+       } catch (const std::exception& e) {
                retval = -1;
                retval = -1;
+               ERR("Failed to launch rotation thread: %s", e.what());
                goto stop_threads;
        }
 
                goto stop_threads;
        }
 
@@ -1943,10 +1941,6 @@ stop_threads:
        rcu_thread_offline();
        rcu_unregister_thread();
 
        rcu_thread_offline();
        rcu_unregister_thread();
 
-       if (rotation_thread_handle) {
-               rotation_thread_handle_destroy(rotation_thread_handle);
-       }
-
        /*
         * After the rotation and timer thread have quit, we can safely destroy
         * the rotation_timer_queue.
        /*
         * After the rotation and timer thread have quit, we can safely destroy
         * the rotation_timer_queue.
@@ -1979,3 +1973,13 @@ exit_set_signal_handler:
                exit(EXIT_FAILURE);
        }
 }
                exit(EXIT_FAILURE);
        }
 }
+
+int main(int argc, char **argv)
+{
+       try {
+               return _main(argc, argv);
+       } catch (const std::exception& e) {
+               ERR_FMT("Unhandled exception caught by main thread: {}", e.what());
+               abort();
+       }
+}
This page took 0.0424 seconds and 4 git commands to generate.