sessiond: open_packets: use user_space_consumer_channel_keys util
[lttng-tools.git] / src / bin / lttng-sessiond / kernel-consumer.cpp
index 15558f207c219d9294d318c40261c86d882dc7ec..f0b1ae4f753799399c72d08ff4f9d0089f9752c3 100644 (file)
@@ -16,6 +16,7 @@
 #include <common/common.hpp>
 #include <common/compat/string.hpp>
 #include <common/defaults.hpp>
+#include <common/urcu.hpp>
 
 #include <inttypes.h>
 #include <stdio.h>
@@ -27,7 +28,7 @@ static char *create_channel_path(struct consumer_output *consumer, size_t *consu
 {
        int ret;
        char tmp_path[PATH_MAX];
-       char *pathname = NULL;
+       char *pathname = nullptr;
 
        LTTNG_ASSERT(consumer);
 
@@ -75,7 +76,7 @@ static char *create_channel_path(struct consumer_output *consumer, size_t *consu
 
 error:
        free(pathname);
-       return NULL;
+       return nullptr;
 }
 
 /*
@@ -87,14 +88,14 @@ static int kernel_consumer_add_channel(struct consumer_socket *sock,
                                       unsigned int monitor)
 {
        int ret;
-       char *pathname = NULL;
+       char *pathname = nullptr;
        struct lttcomm_consumer_msg lkm;
        struct consumer_output *consumer;
        enum lttng_error_code status;
-       struct ltt_session *session = NULL;
        struct lttng_channel_extended *channel_attr_extended;
        bool is_local_trace;
        size_t consumer_path_offset = 0;
+       const lttng::urcu::read_lock_guard read_lock;
 
        /* Safety net */
        LTTNG_ASSERT(channel);
@@ -164,20 +165,26 @@ static int kernel_consumer_add_channel(struct consumer_socket *sock,
        }
 
        health_code_update();
-       rcu_read_lock();
-       session = session_find_by_id(ksession->id);
-       LTTNG_ASSERT(session);
-       ASSERT_LOCKED(session->lock);
-       ASSERT_SESSION_LIST_LOCKED();
-
-       status = notification_thread_command_add_channel(the_notification_thread_handle,
-                                                        session->id,
-                                                        channel->channel->name,
-                                                        channel->key,
-                                                        LTTNG_DOMAIN_KERNEL,
-                                                        channel->channel->attr.subbuf_size *
-                                                                channel->channel->attr.num_subbuf);
-       rcu_read_unlock();
+
+       try {
+               const auto session = ltt_session::find_session(ksession->id);
+
+               ASSERT_SESSION_LIST_LOCKED();
+
+               status = notification_thread_command_add_channel(
+                       the_notification_thread_handle,
+                       session->id,
+                       channel->channel->name,
+                       channel->key,
+                       LTTNG_DOMAIN_KERNEL,
+                       channel->channel->attr.subbuf_size * channel->channel->attr.num_subbuf);
+       } catch (const lttng::sessiond::exceptions::session_not_found_error& ex) {
+               ERR_FMT("Fatal error during the creation of a kernel channel: {}, location='{}'",
+                       ex.what(),
+                       ex.source_location);
+               abort();
+       }
+
        if (status != LTTNG_OK) {
                ret = -1;
                goto error;
@@ -186,9 +193,6 @@ static int kernel_consumer_add_channel(struct consumer_socket *sock,
        channel->published_to_notification_thread = true;
 
 error:
-       if (session) {
-               session_put(session);
-       }
        free(pathname);
        return ret;
 }
@@ -206,7 +210,7 @@ int kernel_consumer_add_metadata(struct consumer_socket *sock,
        struct lttcomm_consumer_msg lkm;
        struct consumer_output *consumer;
 
-       rcu_read_lock();
+       const lttng::urcu::read_lock_guard read_lock;
 
        /* Safety net */
        LTTNG_ASSERT(ksession);
@@ -262,7 +266,6 @@ int kernel_consumer_add_metadata(struct consumer_socket *sock,
        health_code_update();
 
 error:
-       rcu_read_unlock();
        return ret;
 }
 
@@ -361,7 +364,7 @@ int kernel_consumer_send_channel_streams(struct consumer_socket *sock,
        LTTNG_ASSERT(ksession->consumer);
        LTTNG_ASSERT(sock);
 
-       rcu_read_lock();
+       const lttng::urcu::read_lock_guard read_lock;
 
        /* Bail out if consumer is disabled */
        if (!ksession->consumer->enabled) {
@@ -394,7 +397,6 @@ int kernel_consumer_send_channel_streams(struct consumer_socket *sock,
        }
 
 error:
-       rcu_read_unlock();
        return ret;
 }
 
This page took 0.024788 seconds and 4 git commands to generate.