/*
* 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,
+ const struct lttng_event_context *event_context, int kwpipe)
{
int ret, chan_kern_created = 0, chan_ust_created = 0;
- char *app_ctx_provider_name = NULL, *app_ctx_name = NULL;
+ const enum lttng_domain_type domain = cmd_ctx->lsm.domain.type;
+ const struct ltt_session *session = cmd_ctx->session;
+ const char *channel_name = cmd_ctx->lsm.u.context.channel_name;
/*
* 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);
chan_kern_created = 1;
}
/* Add kernel context to kernel tracer */
- ret = context_kernel_add(session->kernel_session, ctx, channel_name);
+ ret = context_kernel_add(session->kernel_session,
+ event_context, channel_name);
if (ret != LTTNG_OK) {
goto error;
}
chan_ust_created = 1;
}
- 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;
+ ret = context_ust_add(usess, domain, event_context,
+ channel_name);
if (ret != LTTNG_OK) {
goto error;
}
trace_ust_destroy_channel(uchan);
}
end:
- free(app_ctx_provider_name);
- free(app_ctx_name);
return ret;
}
/*
* 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_payload *reply)
{
+ enum lttng_error_code ret_code;
int ret;
- ssize_t nb_fields = 0;
+ unsigned int i, nb_fields;
+ struct lttng_event_field *fields = NULL;
+ struct lttcomm_list_command_header reply_command_header = {};
+ size_t reply_command_header_offset;
+
+ assert(reply);
+
+ /* Reserve space for command reply header. */
+ reply_command_header_offset = reply->buffer.size;
+ ret = lttng_dynamic_buffer_set_size(&reply->buffer,
+ reply_command_header_offset +
+ sizeof(struct lttcomm_list_command_header));
+ if (ret) {
+ ret_code = LTTNG_ERR_NOMEM;
+ goto error;
+ }
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;
+ }
+
+ nb_fields = ret;
+
+ for (i = 0; i < nb_fields; i++) {
+ ret = lttng_event_field_serialize(&fields[i], reply);
+ if (ret) {
+ ret_code = LTTNG_ERR_NOMEM;
+ goto error;
+ }
+ }
+
+ if (nb_fields > UINT32_MAX) {
+ ERR("Tracepoint field count would overflow the tracepoint field listing command's reply");
+ ret_code = LTTNG_ERR_OVERFLOW;
goto error;
}
- return nb_fields;
+ /* Update command reply header. */
+ reply_command_header.count = (uint32_t) nb_fields;
+
+ memcpy(reply->buffer.data + reply_command_header_offset, &reply_command_header,
+ sizeof(reply_command_header));
+
+ 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(