Handle application context cmd
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 3 Feb 2016 22:07:27 +0000 (17:07 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 5 Feb 2016 23:13:15 +0000 (18:13 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/lttng/ust-abi.h
include/lttng/ust-events.h
liblttng-ust/lttng-events.c
liblttng-ust/lttng-ust-abi.c
liblttng-ust/lttng-ust-comm.c

index 6ea64c8708e6fb2b36e3ee6c99274586c97d18e2..126e61248487ed05941f2d24875bec7ddf66c4d3 100644 (file)
@@ -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 {
index f3ade45c43558acddedefc5baf33d0a59798bef3..9eed21ef0b2867c40b19e21144641a19aafc73d8 100644 (file)
@@ -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);
 
index f6db6e8a351d495e3e9cd2626e14fece8c21af49..d09c97ca2b1995a7de7d875145f7c9d79573f94e 100644 (file)
@@ -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;
        }
index c5cc42b727c107a26d1466cea45227072643aa0c..762c9017aca96bf35b9971a8dd3b63409f19f2e3 100644 (file)
@@ -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);
index 1387aa82197f63e43dad5439368bec214fc2c1ae..3108e3826a4ed80eda4f7e425e6f1b64b73a8b7f 100644 (file)
@@ -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,
This page took 0.03198 seconds and 5 git commands to generate.