LTTNG_UST_CONTEXT_IP = 4,
LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER = 5,
LTTNG_UST_CONTEXT_CPU_ID = 6,
+ LTTNG_UST_CONTEXT_APP_CONTEXT = 7,
};
struct lttng_ust_perf_counter_ctx {
union {
struct lttng_ust_perf_counter_ctx perf_counter;
+ struct {
+ /* Includes trailing '\0'. */
+ uint32_t provider_name_len;
+ uint32_t ctx_name_len;
+ } app_ctx;
char padding[LTTNG_UST_CONTEXT_PADDING2];
} u;
} LTTNG_PACKED;
* API used by sessiond.
*/
+struct lttng_ust_context_attr {
+ enum lttng_ust_context_type ctx;
+ union {
+ struct lttng_ust_perf_counter_ctx perf_counter;
+ struct {
+ char *provider_name;
+ char *ctx_name;
+ } app_ctx;
+ } u;
+};
+
/*
* Error values: all the following functions return:
* >= 0: Success (LTTNG_UST_OK)
int ustctl_create_event(int sock, struct lttng_ust_event *ev,
struct lttng_ust_object_data *channel_data,
struct lttng_ust_object_data **event_data);
-int ustctl_add_context(int sock, struct lttng_ust_context *ctx,
+int ustctl_add_context(int sock, struct lttng_ust_context_attr *ctx,
struct lttng_ust_object_data *obj_data,
struct lttng_ust_object_data **context_data);
int ustctl_set_filter(int sock, struct lttng_ust_filter_bytecode *bytecode,
return 0;
}
-int ustctl_add_context(int sock, struct lttng_ust_context *ctx,
+int ustctl_add_context(int sock, struct lttng_ust_context_attr *ctx,
struct lttng_ust_object_data *obj_data,
struct lttng_ust_object_data **_context_data)
{
struct ustcomm_ust_msg lum;
struct ustcomm_ust_reply lur;
- struct lttng_ust_object_data *context_data;
+ struct lttng_ust_object_data *context_data = NULL;
+ char *buf = NULL;
+ size_t len;
int ret;
- if (!obj_data || !_context_data)
- return -EINVAL;
+ if (!obj_data || !_context_data) {
+ ret = -EINVAL;
+ goto end;
+ }
context_data = zmalloc(sizeof(*context_data));
- if (!context_data)
- return -ENOMEM;
+ if (!context_data) {
+ ret = -ENOMEM;
+ goto end;
+ }
context_data->type = LTTNG_UST_OBJECT_TYPE_CONTEXT;
memset(&lum, 0, sizeof(lum));
lum.handle = obj_data->handle;
lum.cmd = LTTNG_UST_CONTEXT;
- lum.u.context = *ctx;
- ret = ustcomm_send_app_cmd(sock, &lum, &lur);
- if (ret) {
- free(context_data);
- return ret;
+
+ lum.u.context.ctx = ctx->ctx;
+ switch (ctx->ctx) {
+ case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER:
+ lum.u.context.u.perf_counter = ctx->u.perf_counter;
+ break;
+ case LTTNG_UST_CONTEXT_APP_CONTEXT:
+ {
+ size_t provider_name_len = strlen(
+ ctx->u.app_ctx.provider_name) + 1;
+ size_t ctx_name_len = strlen(ctx->u.app_ctx.ctx_name) + 1;
+
+ lum.u.context.u.app_ctx.provider_name_len = provider_name_len;
+ lum.u.context.u.app_ctx.ctx_name_len = ctx_name_len;
+
+ len = provider_name_len + ctx_name_len;
+ buf = zmalloc(len);
+ if (!buf) {
+ ret = -ENOMEM;
+ goto end;
+ }
+ memcpy(buf, ctx->u.app_ctx.provider_name,
+ provider_name_len);
+ memcpy(buf + provider_name_len, ctx->u.app_ctx.ctx_name,
+ ctx_name_len);
+ break;
+ }
+ default:
+ break;
+ }
+ ret = ustcomm_send_app_msg(sock, &lum);
+ if (ret)
+ goto end;
+ if (buf) {
+ /* send var len ctx_name */
+ ret = ustcomm_send_unix_sock(sock, buf, len);
+ if (ret < 0) {
+ goto end;
+ }
+ if (ret != len) {
+ ret = -EINVAL;
+ goto end;
+ }
+ }
+ ret = ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd);
+ if (ret < 0) {
+ goto end;
}
context_data->handle = -1;
DBG("Context created successfully");
*_context_data = context_data;
+ context_data = NULL;
+end:
+ free(context_data);
+ free(buf);
return ret;
}