From d174444dd0631c95a9bf943b0a4efc7bec61c511 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 3 Feb 2016 17:07:27 -0500 Subject: [PATCH] Handle application context cmd Signed-off-by: Mathieu Desnoyers --- include/lttng/ust-abi.h | 3 ++ include/lttng/ust-events.h | 1 + liblttng-ust/lttng-events.c | 4 +++ liblttng-ust/lttng-ust-abi.c | 5 +-- liblttng-ust/lttng-ust-comm.c | 59 +++++++++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 2 deletions(-) diff --git a/include/lttng/ust-abi.h b/include/lttng/ust-abi.h index 6ea64c87..126e6124 100644 --- a/include/lttng/ust-abi.h +++ b/include/lttng/ust-abi.h @@ -307,6 +307,9 @@ union ust_args { struct { struct lttng_ust_field_iter entry; } field_list; + struct { + char *ctxname; + } app_context; }; struct lttng_ust_objd_ops { diff --git a/include/lttng/ust-events.h b/include/lttng/ust-events.h index f3ade45c..9eed21ef 100644 --- a/include/lttng/ust-events.h +++ b/include/lttng/ust-events.h @@ -629,6 +629,7 @@ int lttng_enabler_attach_exclusion(struct lttng_enabler *enabler, struct lttng_ust_excluder_node *excluder); int lttng_attach_context(struct lttng_ust_context *context_param, + union ust_args *uargs, struct lttng_ctx **ctx, struct lttng_session *session); int lttng_session_context_init(struct lttng_ctx **ctx); diff --git a/liblttng-ust/lttng-events.c b/liblttng-ust/lttng-events.c index f6db6e8a..d09c97ca 100644 --- a/liblttng-ust/lttng-events.c +++ b/liblttng-ust/lttng-events.c @@ -962,6 +962,7 @@ int lttng_enabler_attach_exclusion(struct lttng_enabler *enabler, } int lttng_attach_context(struct lttng_ust_context *context_param, + union ust_args *uargs, struct lttng_ctx **ctx, struct lttng_session *session) { /* @@ -996,6 +997,9 @@ int lttng_attach_context(struct lttng_ust_context *context_param, return lttng_add_ip_to_ctx(ctx); case LTTNG_UST_CONTEXT_CPU_ID: return lttng_add_cpu_id_to_ctx(ctx); + case LTTNG_UST_CONTEXT_APP_CONTEXT: + return lttng_ust_add_app_context_to_ctx_rcu(uargs->app_context.ctxname, + ctx); default: return -EINVAL; } diff --git a/liblttng-ust/lttng-ust-abi.c b/liblttng-ust/lttng-ust-abi.c index c5cc42b7..762c9017 100644 --- a/liblttng-ust/lttng-ust-abi.c +++ b/liblttng-ust/lttng-ust-abi.c @@ -335,9 +335,10 @@ long lttng_abi_tracer_version(int objd, static long lttng_abi_add_context(int objd, struct lttng_ust_context *context_param, + union ust_args *uargs, struct lttng_ctx **ctx, struct lttng_session *session) { - return lttng_attach_context(context_param, ctx, session); + return lttng_attach_context(context_param, uargs, ctx, session); } /** @@ -885,7 +886,7 @@ long lttng_channel_cmd(int objd, unsigned int cmd, unsigned long arg, } case LTTNG_UST_CONTEXT: return lttng_abi_add_context(objd, - (struct lttng_ust_context *) arg, + (struct lttng_ust_context *) arg, uargs, &channel->ctx, channel->session); case LTTNG_UST_ENABLE: return lttng_channel_enable(channel); diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index 1387aa82..3108e382 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -588,6 +588,7 @@ int handle_message(struct sock_info *sock_info, const struct lttng_ust_objd_ops *ops; struct ustcomm_ust_reply lur; union ust_args args; + char ctxstr[LTTNG_UST_SYM_NAME_LEN]; /* App context string. */ ssize_t len; memset(&lur, 0, sizeof(lur)); @@ -807,6 +808,64 @@ int handle_message(struct sock_info *sock_info, ret = -ENOSYS; break; } + case LTTNG_UST_CONTEXT: + switch (lum->u.context.ctx) { + case LTTNG_UST_CONTEXT_APP_CONTEXT: + { + char *p; + size_t ctxlen, recvlen; + + ctxlen = strlen("$app.") + lum->u.context.u.app_ctx.provider_name_len - 1 + + strlen(":") + lum->u.context.u.app_ctx.ctx_name_len; + if (ctxlen >= LTTNG_UST_SYM_NAME_LEN) { + ERR("Application context string length size is too large: %zu bytes", + ctxlen); + ret = -EINVAL; + goto error; + } + strcpy(ctxstr, "$app."); + p = &ctxstr[strlen("$app.")]; + recvlen = ctxlen - strlen("$app."); + len = ustcomm_recv_unix_sock(sock, p, recvlen); + switch (len) { + case 0: /* orderly shutdown */ + ret = 0; + goto error; + default: + if (len == recvlen) { + DBG("app context data received"); + break; + } else if (len < 0) { + DBG("Receive failed from lttng-sessiond with errno %d", (int) -len); + if (len == -ECONNRESET) { + ERR("%s remote end closed connection", sock_info->name); + ret = len; + goto error; + } + ret = len; + goto error; + } else { + DBG("incorrect app context data message size: %zd", len); + ret = -EINVAL; + goto error; + } + } + /* Put : between provider and ctxname. */ + p[lum->u.context.u.app_ctx.provider_name_len - 1] = ':'; + args.app_context.ctxname = ctxstr; + break; + } + default: + break; + } + if (ops->cmd) { + ret = ops->cmd(lum->handle, lum->cmd, + (unsigned long) &lum->u, + &args, sock_info); + } else { + ret = -ENOSYS; + } + break; default: if (ops->cmd) ret = ops->cmd(lum->handle, lum->cmd, -- 2.34.1