X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fcmd.c;h=829e59dd4b67aad2e9003e3b33a16310a09c6645;hb=b7238f7cfdcc67f4c254c03004989156c13c4c15;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..829e59dd4 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -431,14 +431,14 @@ static enum lttng_error_code list_lttng_ust_global_events(char *channel_name, tmp = lttng_event_create(); if (!tmp) { ret_code = LTTNG_ERR_NOMEM; - goto end; + goto error; } if (lttng_strncpy(tmp->name, uevent->attr.name, LTTNG_SYMBOL_NAME_LEN)) { ret_code = LTTNG_ERR_FATAL; lttng_event_destroy(tmp); - goto end; + goto error; } tmp->name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; @@ -1305,7 +1305,7 @@ static int cmd_enable_channel_internal(struct ltt_session *session, attr = lttng_channel_copy(_attr); if (!attr) { - ret = -LTTNG_ERR_NOMEM; + ret = LTTNG_ERR_NOMEM; goto end; } @@ -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; } @@ -2628,31 +2650,43 @@ error: /* * Command LTTNG_LIST_TRACEPOINT_FIELDS processed by the client thread. */ -ssize_t cmd_list_tracepoint_fields(enum lttng_domain_type domain, - struct lttng_event_field **fields) +enum lttng_error_code cmd_list_tracepoint_fields(enum lttng_domain_type domain, + struct lttng_dynamic_buffer *buffer, unsigned int *nb_fields) { + enum lttng_error_code ret_code; int ret; - ssize_t nb_fields = 0; + unsigned int i; + struct lttng_event_field *fields = NULL; switch (domain) { case LTTNG_DOMAIN_UST: - nb_fields = ust_app_list_event_fields(fields); - if (nb_fields < 0) { - ret = LTTNG_ERR_UST_LIST_FAIL; + ret = ust_app_list_event_fields(&fields); + if (ret < 0) { + ret_code = LTTNG_ERR_UST_LIST_FAIL; goto error; } break; case LTTNG_DOMAIN_KERNEL: default: /* fall-through */ - ret = LTTNG_ERR_UND; + ret_code = LTTNG_ERR_UND; goto error; } - return nb_fields; + *nb_fields = ret; + + for (i = 0; i < *nb_fields; i++) { + ret = lttng_event_field_serialize(&fields[i], buffer); + if (ret) { + ret_code = -LTTNG_ERR_NOMEM; + goto error; + } + } + + ret_code = LTTNG_OK; error: - /* Return negative value to differentiate return code */ - return -ret; + free(fields); + return ret_code; } enum lttng_error_code cmd_list_syscalls( @@ -2832,7 +2866,7 @@ int cmd_start_trace(struct ltt_session *session) */ session->rotated_after_last_stop = false; - if (session->rotate_timer_period) { + if (session->rotate_timer_period && !session->rotation_schedule_timer_enabled) { int int_ret = timer_session_rotation_schedule_timer_start( session, session->rotate_timer_period); @@ -3771,6 +3805,7 @@ enum lttng_error_code cmd_list_channels(enum lttng_domain_type domain, extended->lost_packets = lost_packets; ret = lttng_channel_serialize(channel, buffer); + lttng_channel_destroy(channel); if (ret) { ret = -1; break;