Fix: Missing rcu_read_lock in ust_app_get_nb_stream()
[lttng-tools.git] / src / bin / lttng-sessiond / ust-app.c
index 5aad28bbc6d57b458935578f002c658db82ecede..0ae02c32455819f82e1ee33380d54dc124aff878 100644 (file)
@@ -825,16 +825,8 @@ struct ust_app_session *alloc_ust_app_session(struct ust_app *app)
 
        ua_sess->handle = -1;
        ua_sess->channels = lttng_ht_new(0, LTTNG_HT_TYPE_STRING);
-       pthread_mutex_init(&ua_sess->lock, NULL);
-
-       /* Set default metadata channel attribute. */
-       ua_sess->metadata_attr.overwrite = DEFAULT_CHANNEL_OVERWRITE;
-       ua_sess->metadata_attr.subbuf_size = default_get_metadata_subbuf_size();
-       ua_sess->metadata_attr.num_subbuf = DEFAULT_METADATA_SUBBUF_NUM;
-       ua_sess->metadata_attr.switch_timer_interval = DEFAULT_METADATA_SWITCH_TIMER;
-       ua_sess->metadata_attr.read_timer_interval = DEFAULT_METADATA_READ_TIMER;
-       ua_sess->metadata_attr.output = LTTNG_UST_MMAP;
        ua_sess->metadata_attr.type = LTTNG_UST_CHAN_METADATA;
+       pthread_mutex_init(&ua_sess->lock, NULL);
 
        return ua_sess;
 
@@ -1454,7 +1446,32 @@ int create_ust_event(struct ust_app *app, struct ust_app_session *ua_sess,
        }
 
        /* If event not enabled, disable it on the tracer */
-       if (ua_event->enabled == 0) {
+       if (ua_event->enabled) {
+               /*
+                * We now need to explicitly enable the event, since it
+                * is now disabled at creation.
+                */
+               ret = enable_ust_event(app, ua_sess, ua_event);
+               if (ret < 0) {
+                       /*
+                        * If we hit an EPERM, something is wrong with our enable call. If
+                        * we get an EEXIST, there is a problem on the tracer side since we
+                        * just created it.
+                        */
+                       switch (ret) {
+                       case -LTTNG_UST_ERR_PERM:
+                               /* Code flow problem */
+                               assert(0);
+                       case -LTTNG_UST_ERR_EXIST:
+                               /* It's OK for our use case. */
+                               ret = 0;
+                               break;
+                       default:
+                               break;
+                       }
+                       goto error;
+               }
+       } else {
                ret = disable_ust_event(app, ua_sess, ua_event);
                if (ret < 0) {
                        /*
@@ -1617,6 +1634,8 @@ static void shadow_copy_session(struct ust_app_session *ua_sess,
        ua_sess->consumer = usess->consumer;
        ua_sess->output_traces = usess->output_traces;
        ua_sess->live_timer_interval = usess->live_timer_interval;
+       copy_channel_attr_to_ustctl(&ua_sess->metadata_attr,
+                       &usess->metadata_attr);
 
        switch (ua_sess->buffer_type) {
        case LTTNG_BUFFER_PER_PID:
@@ -5105,10 +5124,12 @@ unsigned int ust_app_get_nb_stream(struct ltt_ust_session *usess)
                cds_list_for_each_entry(reg, &usess->buffer_reg_uid_list, lnode) {
                        struct buffer_reg_channel *reg_chan;
 
+                       rcu_read_lock();
                        cds_lfht_for_each_entry(reg->registry->channels->ht, &iter.iter,
                                        reg_chan, node.node) {
                                ret += reg_chan->stream_count;
                        }
+                       rcu_read_unlock();
                }
                break;
        }
This page took 0.023822 seconds and 4 git commands to generate.