From d5979e4a295b782fb44a1dc61fb4e01c47bcdf2c Mon Sep 17 00:00:00 2001 From: David Goulet Date: Tue, 25 Jun 2013 12:30:59 -0400 Subject: [PATCH] Fix: destroy default created channel if add-context fails Fixes #554 Signed-off-by: David Goulet --- src/bin/lttng-sessiond/cmd.c | 27 +++++++++++++++++++++++++-- src/bin/lttng-sessiond/trace-ust.c | 17 +++++++++++++++++ src/bin/lttng-sessiond/trace-ust.h | 8 ++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 9b7306b79..a23a2b761 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -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; } diff --git a/src/bin/lttng-sessiond/trace-ust.c b/src/bin/lttng-sessiond/trace-ust.c index 51632bad4..2c63ef0b5 100644 --- a/src/bin/lttng-sessiond/trace-ust.c +++ b/src/bin/lttng-sessiond/trace-ust.c @@ -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. */ diff --git a/src/bin/lttng-sessiond/trace-ust.h b/src/bin/lttng-sessiond/trace-ust.h index b21d8c2a7..dcb45c237 100644 --- a/src/bin/lttng-sessiond/trace-ust.h +++ b/src/bin/lttng-sessiond/trace-ust.h @@ -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 */ -- 2.34.1