Fix: filter attach vs event enable race
[lttng-tools.git] / src / bin / lttng-sessiond / ust-app.c
index 5aad28bbc6d57b458935578f002c658db82ecede..b0e47a086f575284de902af55df81737189f86bb 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:
This page took 0.024735 seconds and 4 git commands to generate.