Fix: destroy default created channel if add-context fails
authorDavid Goulet <dgoulet@efficios.com>
Tue, 25 Jun 2013 16:30:59 +0000 (12:30 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Tue, 25 Jun 2013 16:30:59 +0000 (12:30 -0400)
Fixes #554

Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/trace-ust.c
src/bin/lttng-sessiond/trace-ust.h

index 9b7306b794668b0b75831306a0a3eeacc9f20625..a23a2b761eac462a4b48869a36b5138a3b71413f 100644 (file)
@@ -1076,7 +1076,7 @@ error:
 int cmd_add_context(struct ltt_session *session, int domain,
                char *channel_name, struct lttng_event_context *ctx, int kwpipe)
 {
-       int ret;
+       int ret, chan_kern_created = 0, chan_ust_created = 0;
 
        switch (domain) {
        case LTTNG_DOMAIN_KERNEL:
@@ -1088,6 +1088,7 @@ int cmd_add_context(struct ltt_session *session, int domain,
                        if (ret != LTTNG_OK) {
                                goto error;
                        }
+                       chan_kern_created = 1;
                }
 
                /* Add kernel context to kernel tracer */
@@ -1118,6 +1119,7 @@ int cmd_add_context(struct ltt_session *session, int domain,
                                goto error;
                        }
                        free(attr);
+                       chan_ust_created = 1;
                }
 
                ret = context_ust_add(usess, domain, ctx, channel_name);
@@ -1136,9 +1138,30 @@ int cmd_add_context(struct ltt_session *session, int domain,
                goto error;
        }
 
-       ret = LTTNG_OK;
+       return LTTNG_OK;
 
 error:
+       if (chan_kern_created) {
+               struct ltt_kernel_channel *kchan =
+                       trace_kernel_get_channel_by_name(DEFAULT_CHANNEL_NAME,
+                                       session->kernel_session);
+               /* Created previously, this should NOT fail. */
+               assert(kchan);
+               kernel_destroy_channel(kchan);
+       }
+
+       if (chan_ust_created) {
+               struct ltt_ust_channel *uchan =
+                       trace_ust_find_channel_by_name(
+                                       session->ust_session->domain_global.channels,
+                                       DEFAULT_CHANNEL_NAME);
+               /* Created previously, this should NOT fail. */
+               assert(uchan);
+               /* Remove from the channel list of the session. */
+               trace_ust_delete_channel(session->ust_session->domain_global.channels,
+                               uchan);
+               trace_ust_destroy_channel(uchan);
+       }
        return ret;
 }
 
index 51632bad4ed602bcbc52fc769cc346bb709c74b3..2c63ef0b5e65f7149e28eca47d6730cfeee3c9aa 100644 (file)
@@ -571,6 +571,23 @@ void trace_ust_destroy_channel(struct ltt_ust_channel *channel)
        call_rcu(&channel->node.head, destroy_channel_rcu);
 }
 
+/*
+ * Remove an UST channel from a channel HT.
+ */
+void trace_ust_delete_channel(struct lttng_ht *ht,
+               struct ltt_ust_channel *channel)
+{
+       int ret;
+       struct lttng_ht_iter iter;
+
+       assert(ht);
+       assert(channel);
+
+       iter.iter.node = &channel->node.node;
+       ret = lttng_ht_del(ht, &iter);
+       assert(!ret);
+}
+
 /*
  * Cleanup ust metadata structure.
  */
index b21d8c2a712bad7e2622b033e2761651905d2182..dcb45c2373d802fa92d04adbedd393d3d310b6ad 100644 (file)
@@ -160,6 +160,8 @@ struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
 struct ltt_ust_metadata *trace_ust_create_metadata(char *path);
 struct ltt_ust_context *trace_ust_create_context(
                struct lttng_event_context *ctx);
+void trace_ust_delete_channel(struct lttng_ht *ht,
+               struct ltt_ust_channel *channel);
 
 /*
  * Destroy functions free() the data structure and remove from linked list if
@@ -241,6 +243,12 @@ static inline struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
 {
        return NULL;
 }
+static inline
+void trace_ust_delete_channel(struct lttng_ht *ht,
+               struct ltt_ust_channel *channel)
+{
+       return;
+}
 
 #endif /* HAVE_LIBLTTNG_UST_CTL */
 
This page took 0.030241 seconds and 4 git commands to generate.