X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;ds=sidebyside;f=src%2Fbin%2Flttng-sessiond%2Fkernel-consumer.cpp;h=b5ccd47dd27ac2947e40b944c3f1ea778fe8f61f;hb=HEAD;hp=15558f207c219d9294d318c40261c86d882dc7ec;hpb=28ab034a2c3582d07d3423d2d746731f87d3969f;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/kernel-consumer.cpp b/src/bin/lttng-sessiond/kernel-consumer.cpp index 15558f207..f0b1ae4f7 100644 --- a/src/bin/lttng-sessiond/kernel-consumer.cpp +++ b/src/bin/lttng-sessiond/kernel-consumer.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -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; }