X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fclient.cpp;h=4c1f6954b952ae1c4d553c5e52a71d48569ffc79;hb=f46376a14da2eb796690cb4e718e8b213839d6ea;hp=189c8eb34f4e9968408bc0789d1f83cf4f0122db;hpb=8ddd72efb54e568ddead0aa3fbc05a3ced24da7d;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/client.cpp b/src/bin/lttng-sessiond/client.cpp index 189c8eb34..4c1f6954b 100644 --- a/src/bin/lttng-sessiond/client.cpp +++ b/src/bin/lttng-sessiond/client.cpp @@ -583,7 +583,8 @@ error_create: /* * Count number of session permitted by uid/gid. */ -static unsigned int lttng_sessions_count(uid_t uid, gid_t gid) +static unsigned int lttng_sessions_count(uid_t uid, + gid_t gid __attribute__((unused))) { unsigned int i = 0; struct ltt_session *session; @@ -763,6 +764,10 @@ static enum lttng_error_code receive_lttng_event(struct command_ctx *cmd_ctx, ssize_t sock_recv_len; enum lttng_error_code ret_code; struct lttng_payload event_payload; + struct lttng_event *local_event = NULL; + char *local_filter_expression = NULL; + struct lttng_bytecode *local_bytecode = NULL; + struct lttng_event_exclusion *local_exclusion = NULL; lttng_payload_init(&event_payload); if (cmd_ctx->lsm.cmd_type == LTTNG_ENABLE_EVENT) { @@ -810,23 +815,111 @@ static enum lttng_error_code receive_lttng_event(struct command_ctx *cmd_ctx, /* Deserialize event. */ { + ssize_t len; struct lttng_payload_view event_view = lttng_payload_view_from_payload( &event_payload, 0, -1); - if (lttng_event_create_from_payload(&event_view, out_event, - out_exclusion, out_filter_expression, - out_bytecode) != event_len) { - ERR("Invalid event received as part of command payload"); + len = lttng_event_create_from_payload(&event_view, &local_event, + &local_exclusion, &local_filter_expression, + &local_bytecode); + + if (len < 0) { + ERR("Failed to create an event from the received buffer"); + ret_code = LTTNG_ERR_INVALID_PROTOCOL; + goto end; + } + + if (len != event_len) { + ERR("Userspace probe location from the received buffer is not the advertised length: header length = %zu" PRIu32 ", payload length = %zd", event_len, len); ret_code = LTTNG_ERR_INVALID_PROTOCOL; goto end; } } + *out_event = local_event; + *out_exclusion = local_exclusion; + *out_filter_expression = local_filter_expression; + *out_bytecode = local_bytecode; + local_event = NULL; + local_exclusion = NULL; + local_filter_expression = NULL; + local_bytecode = NULL; + ret_code = LTTNG_OK; end: lttng_payload_reset(&event_payload); + lttng_event_destroy(local_event); + free(local_filter_expression); + free(local_bytecode); + free(local_exclusion); + return ret_code; +} + +static enum lttng_error_code receive_lttng_event_context( + const struct command_ctx *cmd_ctx, + int sock, + int *sock_error, + struct lttng_event_context **out_event_context) +{ + int ret; + const size_t event_context_len = + (size_t) cmd_ctx->lsm.u.context.length; + ssize_t sock_recv_len; + enum lttng_error_code ret_code; + struct lttng_payload event_context_payload; + struct lttng_event_context *context = NULL; + + lttng_payload_init(&event_context_payload); + + ret = lttng_dynamic_buffer_set_size(&event_context_payload.buffer, + event_context_len); + if (ret) { + ret_code = LTTNG_ERR_NOMEM; + goto end; + } + + sock_recv_len = lttcomm_recv_unix_sock( + sock, event_context_payload.buffer.data, + event_context_len); + if (sock_recv_len < 0 || sock_recv_len != event_context_len) { + ERR("Failed to receive event context in command payload"); + *sock_error = 1; + ret_code = LTTNG_ERR_INVALID_PROTOCOL; + goto end; + } + + /* Deserialize event. */ + { + ssize_t len; + struct lttng_payload_view event_context_view = + lttng_payload_view_from_payload( + &event_context_payload, 0, -1); + + len = lttng_event_context_create_from_payload( + &event_context_view, &context); + + if (len < 0) { + ERR("Failed to create a event context from the received buffer"); + ret_code = LTTNG_ERR_INVALID_PROTOCOL; + goto end; + } + + if (len != event_context_len) { + ERR("Event context from the received buffer is not the advertised length: expected length = %zu, payload length = %zd", event_context_len, len); + ret_code = LTTNG_ERR_INVALID_PROTOCOL; + goto end; + } + } + + *out_event_context = context; + context = NULL; + ret_code = LTTNG_OK; + +end: + lttng_event_context_destroy(context); + lttng_payload_reset(&event_context_payload); return ret_code; } @@ -1299,77 +1392,18 @@ skip_domain: switch (cmd_ctx->lsm.cmd_type) { case LTTNG_ADD_CONTEXT: { - lttng_event_context ctx; + struct lttng_event_context *event_context = NULL; + const enum lttng_error_code ret_code = + receive_lttng_event_context( + cmd_ctx, *sock, sock_error, &event_context); - /* - * An LTTNG_ADD_CONTEXT command might have a supplementary - * payload if the context being added is an application context. - */ - if (cmd_ctx->lsm.u.context.ctx.ctx == - LTTNG_EVENT_CONTEXT_APP_CONTEXT) { - char *provider_name = NULL, *context_name = NULL; - size_t provider_name_len = - cmd_ctx->lsm.u.context.provider_name_len; - size_t context_name_len = - cmd_ctx->lsm.u.context.context_name_len; - - if (provider_name_len == 0 || context_name_len == 0) { - /* - * Application provider and context names MUST - * be provided. - */ - ret = -LTTNG_ERR_INVALID; - goto error; - } - - provider_name = (char *) zmalloc(provider_name_len + 1); - if (!provider_name) { - ret = -LTTNG_ERR_NOMEM; - goto error; - } - cmd_ctx->lsm.u.context.ctx.u.app_ctx.provider_name = - provider_name; - - context_name = (char *) zmalloc(context_name_len + 1); - if (!context_name) { - ret = -LTTNG_ERR_NOMEM; - goto error_add_context; - } - cmd_ctx->lsm.u.context.ctx.u.app_ctx.ctx_name = - context_name; - - ret = lttcomm_recv_unix_sock(*sock, provider_name, - provider_name_len); - if (ret < 0) { - goto error_add_context; - } - - ret = lttcomm_recv_unix_sock(*sock, context_name, - context_name_len); - if (ret < 0) { - goto error_add_context; - } - } - - /* - * cmd_add_context assumes ownership of the provider and context - * names. - */ - ctx = cmd_ctx->lsm.u.context.ctx; - ret = cmd_add_context(cmd_ctx->session, - cmd_ctx->lsm.domain.type, - cmd_ctx->lsm.u.context.channel_name, - &ctx, - the_kernel_poll_pipe[1]); - - cmd_ctx->lsm.u.context.ctx.u.app_ctx.provider_name = NULL; - cmd_ctx->lsm.u.context.ctx.u.app_ctx.ctx_name = NULL; -error_add_context: - free(cmd_ctx->lsm.u.context.ctx.u.app_ctx.provider_name); - free(cmd_ctx->lsm.u.context.ctx.u.app_ctx.ctx_name); - if (ret < 0) { + if (ret_code != LTTNG_OK) { + ret = (int) ret_code; goto error; } + + ret = cmd_add_context(cmd_ctx, event_context, the_kernel_poll_pipe[1]); + lttng_event_context_destroy(event_context); break; } case LTTNG_DISABLE_CHANNEL: @@ -1647,30 +1681,31 @@ error_add_context: } case LTTNG_LIST_TRACEPOINT_FIELDS: { - struct lttng_event_field *fields; - ssize_t nb_fields; + enum lttng_error_code ret_code; + size_t original_payload_size; + size_t payload_size; + const size_t command_header_size = sizeof(struct lttcomm_list_command_header); + + ret = setup_empty_lttng_msg(cmd_ctx); + if (ret) { + ret = LTTNG_ERR_NOMEM; + goto setup_error; + } + + original_payload_size = cmd_ctx->reply_payload.buffer.size; session_lock_list(); - nb_fields = cmd_list_tracepoint_fields(cmd_ctx->lsm.domain.type, - &fields); + ret_code = cmd_list_tracepoint_fields( + cmd_ctx->lsm.domain.type, &cmd_ctx->reply_payload); session_unlock_list(); - if (nb_fields < 0) { - /* Return value is a negative lttng_error_code. */ - ret = -nb_fields; + if (ret_code != LTTNG_OK) { + ret = (int) ret_code; goto error; } - /* - * Setup lttng message with payload size set to the event list size in - * bytes and then copy list into the llm payload. - */ - ret = setup_lttng_msg_no_cmd_header(cmd_ctx, fields, - sizeof(struct lttng_event_field) * nb_fields); - free(fields); - - if (ret < 0) { - goto setup_error; - } + payload_size = cmd_ctx->reply_payload.buffer.size - + command_header_size - original_payload_size; + update_lttng_msg(cmd_ctx, command_header_size, payload_size); ret = LTTNG_OK; break; @@ -2007,8 +2042,7 @@ error_add_context: { lttng_snapshot_output output = cmd_ctx->lsm.u.snapshot_record.output; ret = cmd_snapshot_record(cmd_ctx->session, - &output, - cmd_ctx->lsm.u.snapshot_record.wait); + &output, 0); // RFC: set to zero since it's ignored by cmd_snapshot_record break; } case LTTNG_CREATE_SESSION_EXT: @@ -2401,7 +2435,7 @@ static void cleanup_client_thread(void *data) lttng_pipe_destroy(quit_pipe); } -static void thread_init_cleanup(void *data) +static void thread_init_cleanup(void *data __attribute__((unused))) { set_thread_status(false); }