X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Flib%2Flttng-ctl%2Flttng-ctl.c;fp=src%2Flib%2Flttng-ctl%2Flttng-ctl.c;h=a387202a66e1d192cfa7b586553164ab01d94d8c;hb=b583ad836a07eb17b3abebc9354e49a9ce415492;hp=6b745d0204eb30d1c6517c72d2a6314fd1787858;hpb=166fc58650170d8213cd7d43c68d9a6601336dd0;p=deliverable%2Flttng-tools.git diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 6b745d020..a387202a6 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -804,9 +804,10 @@ int lttng_add_context(struct lttng_handle *handle, const char *channel_name) { int ret; - size_t len = 0; - char *buf = NULL; struct lttcomm_session_msg lsm; + struct lttng_dynamic_buffer buffer; + + lttng_dynamic_buffer_init(&buffer); /* Safety check. Both are mandatory. */ if (handle == NULL || ctx == NULL) { @@ -833,55 +834,18 @@ int lttng_add_context(struct lttng_handle *handle, goto end; } - if (ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT) { - size_t provider_len, ctx_len; - const char *provider_name = ctx->u.app_ctx.provider_name; - const char *ctx_name = ctx->u.app_ctx.ctx_name; - - if (!provider_name || !ctx_name) { - ret = -LTTNG_ERR_INVALID; - goto end; - } - - provider_len = strlen(provider_name); - if (provider_len == 0) { - ret = -LTTNG_ERR_INVALID; - goto end; - } - lsm.u.context.provider_name_len = provider_len; - - ctx_len = strlen(ctx_name); - if (ctx_len == 0) { - ret = -LTTNG_ERR_INVALID; - goto end; - } - lsm.u.context.context_name_len = ctx_len; - - len = provider_len + ctx_len; - buf = zmalloc(len); - if (!buf) { - ret = -LTTNG_ERR_NOMEM; - goto end; - } - - memcpy(buf, provider_name, provider_len); - memcpy(buf + provider_len, ctx_name, ctx_len); + ret = lttng_event_context_serialize(ctx, &buffer); + if (ret) { + ret = -LTTNG_ERR_INVALID; + goto end; } - memcpy(&lsm.u.context.ctx, ctx, sizeof(struct lttng_event_context)); - if (ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT) { - /* - * Don't leak application addresses to the sessiond. - * This is only necessary when ctx is for an app ctx otherwise - * the values inside the union (type & config) are overwritten. - */ - lsm.u.context.ctx.u.app_ctx.provider_name = NULL; - lsm.u.context.ctx.u.app_ctx.ctx_name = NULL; - } + lsm.u.context.length = buffer.size; - ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, buf, len, NULL); + ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header( + &lsm, buffer.data, buffer.size, NULL); end: - free(buf); + lttng_dynamic_buffer_reset(&buffer); return ret; }