X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Ftrace-kernel.c;h=8e074fd91b0dcbe829f8c053d32ac6e92766d32c;hp=33e5488ef293fde00f2841094f17d92e15e0a834;hb=645328ae989e5f50a3a49c1ac34b2fee287a3d7b;hpb=91b23e997053fb552662f1ad07273f029e00d2e4 diff --git a/src/bin/lttng-sessiond/trace-kernel.c b/src/bin/lttng-sessiond/trace-kernel.c index 33e5488ef..8e074fd91 100644 --- a/src/bin/lttng-sessiond/trace-kernel.c +++ b/src/bin/lttng-sessiond/trace-kernel.c @@ -38,6 +38,13 @@ struct ltt_kernel_channel *trace_kernel_get_channel_by_name( assert(session); assert(name); + /* + * If we receive an empty string for channel name, it means the + * default channel name is requested. + */ + if (name[0] == '\0') + name = DEFAULT_CHANNEL_NAME; + DBG("Trying to find channel %s", name); cds_list_for_each_entry(chan, &session->channel_list.head, list) { @@ -144,14 +151,24 @@ struct ltt_kernel_channel *trace_kernel_create_channel( } memcpy(lkc->channel, chan, sizeof(struct lttng_channel)); + /* + * If we receive an empty string for channel name, it means the + * default channel name is requested. + */ + if (chan->name[0] == '\0') { + strncpy(lkc->channel->name, DEFAULT_CHANNEL_NAME, + sizeof(lkc->channel->name)); + } + lkc->channel->name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; + lkc->fd = -1; lkc->stream_count = 0; lkc->event_count = 0; lkc->enabled = 1; - lkc->ctx = NULL; /* Init linked list */ CDS_INIT_LIST_HEAD(&lkc->events_list.head); CDS_INIT_LIST_HEAD(&lkc->stream_list.head); + CDS_INIT_LIST_HEAD(&lkc->ctx_list); return lkc; @@ -159,6 +176,30 @@ error: return NULL; } +/* + * Allocate and init a kernel context object. + * + * Return the allocated object or NULL on error. + */ +struct ltt_kernel_context *trace_kernel_create_context( + struct lttng_kernel_context *ctx) +{ + struct ltt_kernel_context *kctx; + + kctx = zmalloc(sizeof(*kctx)); + if (!kctx) { + PERROR("zmalloc kernel context"); + goto error; + } + + if (ctx) { + memcpy(&kctx->ctx, ctx, sizeof(kctx->ctx)); + } + +error: + return kctx; +} + /* * Allocate and initialize a kernel event. Set name and event type. * @@ -290,7 +331,7 @@ struct ltt_kernel_stream *trace_kernel_create_stream(const char *name, } /* Set name */ - ret = snprintf(lks->name, sizeof(lks->name), "%s_%d", name, count); + ret = snprintf(lks->name, sizeof(lks->name), "%s_%u", name, count); if (ret < 0) { PERROR("snprintf stream name"); goto error; @@ -358,6 +399,17 @@ void trace_kernel_destroy_event(struct ltt_kernel_event *event) free(event); } +/* + * Cleanup kernel context structure. + */ +void trace_kernel_destroy_context(struct ltt_kernel_context *ctx) +{ + assert(ctx); + + cds_list_del(&ctx->list); + free(ctx); +} + /* * Cleanup kernel channel structure. */ @@ -365,6 +417,7 @@ void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel) { struct ltt_kernel_stream *stream, *stmp; struct ltt_kernel_event *event, *etmp; + struct ltt_kernel_context *ctx, *ctmp; int ret; assert(channel); @@ -388,11 +441,15 @@ void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel) trace_kernel_destroy_event(event); } + /* For each context in the channel list */ + cds_list_for_each_entry_safe(ctx, ctmp, &channel->ctx_list, list) { + trace_kernel_destroy_context(ctx); + } + /* Remove from channel list */ cds_list_del(&channel->list); free(channel->channel); - free(channel->ctx); free(channel); }