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) {
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;
}