From: Mathieu Desnoyers Date: Wed, 3 Feb 2016 22:07:27 +0000 (-0500) Subject: Handle application context cmd X-Git-Tag: v2.8.0-rc1~43 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=8e696cfa579df0d75368a36d049e9c99b24e53f4;p=lttng-ust.git Handle application context cmd Signed-off-by: Mathieu Desnoyers --- 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 cf2443ba..8a568328 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -591,6 +591,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)); @@ -810,6 +811,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,