Clean-up: modernize pretty_xml.cpp
[lttng-tools.git] / src / bin / lttng-sessiond / channel.cpp
index 44c3fd0cf6beda8a394edc117f48c880133a0b44..4e5401295ed43f9d36d87b2e29a78b4f2ca52b72 100644 (file)
@@ -31,10 +31,10 @@ struct lttng_channel *channel_new_default_attr(int dom, enum lttng_buffer_type t
 {
        struct lttng_channel *chan;
        const char *channel_name = DEFAULT_CHANNEL_NAME;
-       struct lttng_channel_extended *extended_attr = NULL;
+       struct lttng_channel_extended *extended_attr = nullptr;
 
        chan = zmalloc<lttng_channel>();
-       if (chan == NULL) {
+       if (chan == nullptr) {
                PERROR("zmalloc channel init");
                goto error_alloc;
        }
@@ -115,7 +115,7 @@ error:
        free(extended_attr);
        free(chan);
 error_alloc:
-       return NULL;
+       return nullptr;
 }
 
 void channel_attr_destroy(struct lttng_channel *channel)
@@ -139,13 +139,13 @@ int channel_kernel_disable(struct ltt_kernel_session *ksession, char *channel_na
        LTTNG_ASSERT(channel_name);
 
        kchan = trace_kernel_get_channel_by_name(channel_name, ksession);
-       if (kchan == NULL) {
+       if (kchan == nullptr) {
                ret = LTTNG_ERR_KERN_CHAN_NOT_FOUND;
                goto error;
        }
 
        /* Only if channel is enabled disable it. */
-       if (kchan->enabled == 1) {
+       if (kchan->enabled) {
                ret = kernel_disable_channel(kchan);
                if (ret < 0 && ret != -EEXIST) {
                        ret = LTTNG_ERR_KERN_CHAN_DISABLE_FAIL;
@@ -170,7 +170,7 @@ enum lttng_error_code channel_kernel_enable(struct ltt_kernel_session *ksession,
        LTTNG_ASSERT(ksession);
        LTTNG_ASSERT(kchan);
 
-       if (kchan->enabled == 0) {
+       if (!kchan->enabled) {
                if (kernel_enable_channel(kchan) < 0) {
                        ret_code = LTTNG_ERR_KERN_CHAN_ENABLE_FAIL;
                        goto error;
@@ -216,14 +216,14 @@ enum lttng_error_code channel_kernel_create(struct ltt_kernel_session *ksession,
                                            int kernel_pipe)
 {
        enum lttng_error_code ret_code;
-       struct lttng_channel *defattr = NULL;
+       struct lttng_channel *defattr = nullptr;
 
        LTTNG_ASSERT(ksession);
 
        /* Creating channel attributes if needed */
-       if (attr == NULL) {
+       if (attr == nullptr) {
                defattr = channel_new_default_attr(LTTNG_DOMAIN_KERNEL, LTTNG_BUFFER_GLOBAL);
-               if (defattr == NULL) {
+               if (defattr == nullptr) {
                        ret_code = LTTNG_ERR_FATAL;
                        goto error;
                }
@@ -284,7 +284,7 @@ enum lttng_error_code channel_ust_enable(struct ltt_ust_session *usess,
                ret_code = LTTNG_ERR_UST_CHAN_EXIST;
                goto end;
        } else {
-               uchan->enabled = 1;
+               uchan->enabled = true;
                DBG2("Channel %s enabled successfully", uchan->name);
        }
 
@@ -321,17 +321,18 @@ enum lttng_error_code channel_ust_create(struct ltt_ust_session *usess,
                                         enum lttng_buffer_type type)
 {
        enum lttng_error_code ret_code = LTTNG_OK;
-       struct ltt_ust_channel *uchan = NULL;
-       struct lttng_channel *defattr = NULL;
+       struct ltt_ust_channel *uchan = nullptr;
+       struct lttng_channel *defattr = nullptr;
        enum lttng_domain_type domain = LTTNG_DOMAIN_UST;
        bool chan_published = false;
+       lttng::urcu::read_lock_guard read_lock;
 
        LTTNG_ASSERT(usess);
 
        /* Creating channel attributes if needed */
-       if (attr == NULL) {
+       if (attr == nullptr) {
                defattr = channel_new_default_attr(LTTNG_DOMAIN_UST, type);
-               if (defattr == NULL) {
+               if (defattr == nullptr) {
                        ret_code = LTTNG_ERR_FATAL;
                        goto error;
                }
@@ -420,17 +421,18 @@ enum lttng_error_code channel_ust_create(struct ltt_ust_session *usess,
 
        /* Create UST channel */
        uchan = trace_ust_create_channel(attr, domain);
-       if (uchan == NULL) {
+       if (uchan == nullptr) {
                ret_code = LTTNG_ERR_FATAL;
                goto error;
        }
 
-       uchan->enabled = 1;
-       if (trace_ust_is_max_id(usess->used_channel_id)) {
+       uchan->enabled = true;
+       if (trace_ust_is_max_id(usess->used_event_container_id)) {
                ret_code = LTTNG_ERR_UST_CHAN_FAIL;
                goto error;
        }
-       uchan->id = trace_ust_get_next_chan_id(usess);
+
+       uchan->id = trace_ust_get_next_event_container_id(usess);
 
        DBG2("Channel %s is being created for UST with buffer %d and id %" PRIu64,
             uchan->name,
@@ -448,8 +450,7 @@ enum lttng_error_code channel_ust_create(struct ltt_ust_session *usess,
        }
 
        /* Adding the channel to the channel hash table. */
-       rcu_read_lock();
-       if (strncmp(uchan->name, DEFAULT_METADATA_NAME, sizeof(uchan->name))) {
+       if (strncmp(uchan->name, DEFAULT_METADATA_NAME, sizeof(uchan->name)) != 0) {
                lttng_ht_add_unique_str(usess->domain_global.channels, &uchan->node);
                chan_published = true;
        } else {
@@ -460,7 +461,6 @@ enum lttng_error_code channel_ust_create(struct ltt_ust_session *usess,
                 */
                memcpy(&usess->metadata_attr, &uchan->attr, sizeof(usess->metadata_attr));
        }
-       rcu_read_unlock();
 
        DBG2("Channel %s created successfully", uchan->name);
        if (domain != LTTNG_DOMAIN_UST) {
@@ -501,12 +501,12 @@ int channel_ust_disable(struct ltt_ust_session *usess, struct ltt_ust_channel *u
        LTTNG_ASSERT(uchan);
 
        /* Already disabled */
-       if (uchan->enabled == 0) {
+       if (!uchan->enabled) {
                DBG2("Channel UST %s already disabled", uchan->name);
                goto end;
        }
 
-       uchan->enabled = 0;
+       uchan->enabled = false;
 
        /*
         * If session is inactive we don't notify the tracer right away. We
@@ -535,7 +535,7 @@ error:
 
 struct lttng_channel *trace_ust_channel_to_lttng_channel(const struct ltt_ust_channel *uchan)
 {
-       struct lttng_channel *channel = NULL, *ret = NULL;
+       struct lttng_channel *channel = nullptr, *ret = nullptr;
 
        channel = lttng_channel_create_internal();
        if (!channel) {
@@ -577,7 +577,7 @@ struct lttng_channel *trace_ust_channel_to_lttng_channel(const struct ltt_ust_ch
        lttng_channel_set_monitor_timer_interval(channel, uchan->monitor_timer_interval);
 
        ret = channel;
-       channel = NULL;
+       channel = nullptr;
 
 end:
        lttng_channel_destroy(channel);
This page took 0.025755 seconds and 4 git commands to generate.