X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fcontext.c;h=6aacbad0ea1c96ad3375739ca908f765f1ba4370;hp=74afd4e0cad5ff87d307de751672ad1ae86bad61;hb=55d097957f5bb8138959ad2202a40d85d49f029e;hpb=601d5acf42ebdb05ff8aa19f12fd9bdad3602781 diff --git a/src/bin/lttng-sessiond/context.c b/src/bin/lttng-sessiond/context.c index 74afd4e0c..6aacbad0e 100644 --- a/src/bin/lttng-sessiond/context.c +++ b/src/bin/lttng-sessiond/context.c @@ -39,6 +39,9 @@ static int add_kctx_all_channels(struct ltt_kernel_session *ksession, int ret; struct ltt_kernel_channel *kchan; + assert(ksession); + assert(kctx); + DBG("Adding kernel context to all channels"); /* Go over all channels */ @@ -64,6 +67,9 @@ static int add_kctx_to_channel(struct lttng_kernel_context *kctx, { int ret; + assert(kchan); + assert(kctx); + DBG("Add kernel context to channel '%s'", kchan->channel->name); ret = kernel_add_channel_context(kchan, kctx); @@ -89,6 +95,10 @@ static int add_uctx_to_channel(struct ltt_ust_session *usess, int domain, struct lttng_ht_iter iter; struct lttng_ht_node_ulong *uctx_node; + assert(usess); + assert(uchan); + assert(ctx); + /* Create ltt UST context */ uctx = trace_ust_create_context(ctx); if (uctx == NULL) { @@ -108,16 +118,21 @@ static int add_uctx_to_channel(struct ltt_ust_session *usess, int domain, goto error; } + rcu_read_lock(); + /* Lookup context before adding it */ lttng_ht_lookup(uchan->ctx, (void *)((unsigned long)uctx->ctx.ctx), &iter); uctx_node = lttng_ht_iter_get_node_ulong(&iter); if (uctx_node != NULL) { ret = -EEXIST; + rcu_read_unlock(); goto error; } /* Add ltt UST context node to ltt UST channel */ lttng_ht_add_unique_ulong(uchan->ctx, &uctx->node); + rcu_read_unlock(); + cds_list_add_tail(&uctx->list, &uchan->ctx_list); DBG("Context UST %d added to channel %s", uctx->ctx.ctx, uchan->name); @@ -138,6 +153,10 @@ int context_kernel_add(struct ltt_kernel_session *ksession, struct ltt_kernel_channel *kchan; struct lttng_kernel_context kctx; + assert(ksession); + assert(ctx); + assert(channel_name); + /* Setup kernel context structure */ switch (ctx->ctx) { case LTTNG_EVENT_CONTEXT_PID: @@ -183,7 +202,7 @@ int context_kernel_add(struct ltt_kernel_session *ksession, LTTNG_SYMBOL_NAME_LEN); kctx.u.perf_counter.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; - if (strlen(channel_name) == 0) { + if (*channel_name == '\0') { ret = add_kctx_all_channels(ksession, &kctx); if (ret != LTTNG_OK) { goto error; @@ -219,6 +238,12 @@ int context_ust_add(struct ltt_ust_session *usess, int domain, struct lttng_ht *chan_ht; struct ltt_ust_channel *uchan = NULL; + assert(usess); + assert(ctx); + assert(channel_name); + + rcu_read_lock(); + /* * Define which channel's hashtable to use from the domain or quit if * unknown domain. @@ -238,7 +263,7 @@ int context_ust_add(struct ltt_ust_session *usess, int domain, } /* Get UST channel if defined */ - if (strlen(channel_name) != 0) { + if (channel_name[0] != '\0') { uchan = trace_ust_find_channel_by_name(chan_ht, channel_name); if (uchan == NULL) { ret = LTTNG_ERR_UST_CHAN_NOT_FOUND; @@ -250,6 +275,7 @@ int context_ust_add(struct ltt_ust_session *usess, int domain, /* Add ctx to channel */ ret = add_uctx_to_channel(usess, domain, uchan, ctx); } else { + rcu_read_lock(); /* Add ctx all events, all channels */ cds_lfht_for_each_entry(chan_ht->ht, &iter.iter, uchan, node.node) { ret = add_uctx_to_channel(usess, domain, uchan, ctx); @@ -258,6 +284,7 @@ int context_ust_add(struct ltt_ust_session *usess, int domain, continue; } } + rcu_read_unlock(); } switch (ret) { @@ -279,5 +306,6 @@ int context_ust_add(struct ltt_ust_session *usess, int domain, } error: + rcu_read_unlock(); return ret; }