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=afb578cfde886754321d7a1c16c9d9d2ce89ec6b;hb=645328ae989e5f50a3a49c1ac34b2fee287a3d7b;hpb=dec56f6cc894de41b312354d360b6a4c09fc199d diff --git a/src/bin/lttng-sessiond/trace-kernel.c b/src/bin/lttng-sessiond/trace-kernel.c index afb578cfd..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. * @@ -191,7 +232,6 @@ struct ltt_kernel_event *trace_kernel_create_event(struct lttng_event *ev) attr->instrumentation = LTTNG_KERNEL_KRETPROBE; attr->u.kretprobe.addr = ev->attr.probe.addr; attr->u.kretprobe.offset = ev->attr.probe.offset; - attr->u.kretprobe.offset = ev->attr.probe.offset; strncpy(attr->u.kretprobe.symbol_name, ev->attr.probe.symbol_name, LTTNG_KERNEL_SYM_NAME_LEN); attr->u.kretprobe.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; @@ -291,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; @@ -359,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. */ @@ -366,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); @@ -389,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); } @@ -421,6 +477,8 @@ void trace_kernel_destroy_metadata(struct ltt_kernel_metadata *metadata) /* * Cleanup kernel session structure + * + * Should *NOT* be called with RCU read-side lock held. */ void trace_kernel_destroy_session(struct ltt_kernel_session *session) {