X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fcmd.c;h=5a6414ebbe4991f48b4450d64d31c32f1d1ce00e;hb=b583ad836a07eb17b3abebc9354e49a9ce415492;hp=efa46cc28128b938f9eee35194f6fe03c6f01055;hpb=166fc58650170d8213cd7d43c68d9a6601336dd0;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index efa46cc28..5a6414ebb 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -1913,27 +1913,54 @@ error: /* * Command LTTNG_ADD_CONTEXT processed by the client thread. */ -int cmd_add_context(struct ltt_session *session, enum lttng_domain_type domain, - char *channel_name, const struct lttng_event_context *ctx, int kwpipe) + +int cmd_add_context(struct command_ctx *cmd_ctx, int sock, int kwpipe) { + struct lttng_event_context *ctx = NULL; int ret, chan_kern_created = 0, chan_ust_created = 0; - char *app_ctx_provider_name = NULL, *app_ctx_name = NULL; + struct lttng_dynamic_buffer buffer; + struct lttng_buffer_view view; + size_t context_len; + ssize_t sock_recv_len; + enum lttng_domain_type domain = cmd_ctx->lsm->domain.type; + struct ltt_session *session = cmd_ctx->session; + const char *channel_name = cmd_ctx->lsm->u.context.channel_name; + + lttng_dynamic_buffer_init(&buffer); + + context_len = (size_t) cmd_ctx->lsm->u.context.length; + ret = lttng_dynamic_buffer_set_size(&buffer, context_len); + if (ret) { + ret = LTTNG_ERR_NOMEM; + goto end; + } + + sock_recv_len = lttcomm_recv_unix_sock(sock, buffer.data, context_len); + if (sock_recv_len < 0 || sock_recv_len != context_len) { + ERR("Failed to receive \"add context\" command payload"); + ret = LTTNG_ERR_INVALID; + goto end; + } + + view = lttng_buffer_view_from_dynamic_buffer(&buffer, 0, -1); + + if (lttng_event_context_create_from_buffer(&view, &ctx) != + context_len) { + ERR("Invalid event context payload received in \"add context\" command"); + ret = LTTNG_ERR_INVALID; + goto end; + } /* * Don't try to add a context if the session has been started at * some point in time before. The tracer does not allow it and would * result in a corrupted trace. */ - if (session->has_been_started) { + if (cmd_ctx->session->has_been_started) { ret = LTTNG_ERR_TRACE_ALREADY_STARTED; goto end; } - if (ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT) { - app_ctx_provider_name = ctx->u.app_ctx.provider_name; - app_ctx_name = ctx->u.app_ctx.ctx_name; - } - switch (domain) { case LTTNG_DOMAIN_KERNEL: assert(session->kernel_session); @@ -2002,10 +2029,6 @@ int cmd_add_context(struct ltt_session *session, enum lttng_domain_type domain, } ret = context_ust_add(usess, domain, ctx, channel_name); - free(app_ctx_provider_name); - free(app_ctx_name); - app_ctx_name = NULL; - app_ctx_provider_name = NULL; if (ret != LTTNG_OK) { goto error; } @@ -2042,8 +2065,7 @@ error: trace_ust_destroy_channel(uchan); } end: - free(app_ctx_provider_name); - free(app_ctx_name); + lttng_event_context_destroy(ctx); return ret; }