Fix: incorrect support for multi-context
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 13 May 2013 10:02:55 +0000 (06:02 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 13 May 2013 10:02:55 +0000 (06:02 -0400)
* Zifei Tong <soariez@gmail.com> wrote:
> I did some debugging one this issue. The problem only occurs when we
> have more than one context field.
> So this will not work, too:
>
> lttng create
> lttng enable-event -a -u
> lttng add-context -u -t vpid
> lttng add-context -u -t vtid
> lttng start
> $@
> lttng stop
> sleep 1
> lttng view
> lttng destroy
>
> The problem I found out is wrong `fields` argument passed into
> `ustcomm_register_channel`.
> The `fields` argument passed is a pointer to the `event_field` of the
> first element in a `lttng_ctx_field` array, but not a
> `lttng_event_field` array as expected.

Fixes #529

Reported-by: Francis Giraldeau <francis.giraldeau@gmail.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/ust-comm.h
liblttng-ust-comm/lttng-ust-comm.c
liblttng-ust/lttng-events.c

index 133426e5e5f5e9e4a75e2b895cce4800013dad31..7f268b7fe08b6c7b4197a8d8c908053d23e28962 100644 (file)
@@ -48,6 +48,7 @@
 #define LTTNG_UST_COMM_REG_MSG_PADDING                 64
 
 struct lttng_event_field;
+struct lttng_ctx_field;
 
 struct ustctl_reg_msg {
        uint32_t magic;
@@ -226,7 +227,7 @@ int ustcomm_register_channel(int sock,
        int session_objd,               /* session descriptor */
        int channel_objd,               /* channel descriptor */
        size_t nr_ctx_fields,
-       const struct lttng_event_field *ctx_fields,
+       const struct lttng_ctx_field *ctx_fields,
        uint32_t *chan_id,              /* channel id (output) */
        int *header_type);              /* header type (output) */
 
index 087424fe66626a6dd393315ccb3fa896c54322ff..5321922d5278f84d544a2005fa955e2d5ad42aa9 100644 (file)
@@ -830,6 +830,47 @@ error_type:
        return ret;
 }
 
+static
+int serialize_ctx_fields(size_t *_nr_write_fields,
+               struct ustctl_field **ustctl_fields,
+               size_t nr_fields,
+               const struct lttng_ctx_field *lttng_fields)
+{
+       struct ustctl_field *fields;
+       int i, ret;
+       size_t nr_write_fields = 0;
+
+       fields = zmalloc(nr_fields * sizeof(*fields));
+       if (!fields)
+               return -ENOMEM;
+
+       for (i = 0; i < nr_fields; i++) {
+               struct ustctl_field *f;
+               const struct lttng_event_field *lf;
+
+               f = &fields[nr_write_fields];
+               lf = &lttng_fields[i].event_field;
+
+               /* skip 'nowrite' fields */
+               if (lf->nowrite)
+                       continue;
+               strncpy(f->name, lf->name, LTTNG_UST_SYM_NAME_LEN);
+               f->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
+               ret = serialize_one_type(&f->type, &lf->type);
+               if (ret)
+                       goto error_type;
+               nr_write_fields++;
+       }
+
+       *_nr_write_fields = nr_write_fields;
+       *ustctl_fields = fields;
+       return 0;
+
+error_type:
+       free(fields);
+       return ret;
+}
+
 /*
  * Returns 0 on success, negative error value on error.
  */
@@ -968,7 +1009,7 @@ int ustcomm_register_channel(int sock,
        int session_objd,               /* session descriptor */
        int channel_objd,               /* channel descriptor */
        size_t nr_ctx_fields,
-       const struct lttng_event_field *ctx_fields,
+       const struct lttng_ctx_field *ctx_fields,
        uint32_t *chan_id,              /* channel id (output) */
        int *header_type)               /* header type (output) */
 {
@@ -982,7 +1023,7 @@ int ustcomm_register_channel(int sock,
                struct ustcomm_notify_channel_reply r;
        } reply;
        size_t fields_len;
-       struct ustctl_field *fields;
+       struct ustctl_field *fields = NULL;
        int ret;
        size_t nr_write_fields = 0;
 
@@ -993,7 +1034,7 @@ int ustcomm_register_channel(int sock,
 
        /* Calculate fields len, serialize fields. */
        if (nr_ctx_fields > 0) {
-               ret = serialize_fields(&nr_write_fields, &fields,
+               ret = serialize_ctx_fields(&nr_write_fields, &fields,
                                nr_ctx_fields, ctx_fields);
                if (ret)
                        return ret;
index e4faf605e6e0eb1d5642fc5dea1b2d4bd0ae5946..a3127a473cba216637b7ad41da287b3372d09b8b 100644 (file)
@@ -260,7 +260,7 @@ int lttng_session_enable(struct lttng_session *session)
         */
        cds_list_for_each_entry(chan, &session->chan_head, node) {
                const struct lttng_ctx *ctx;
-               const struct lttng_event_field *fields = NULL;
+               const struct lttng_ctx_field *fields = NULL;
                size_t nr_fields = 0;
                uint32_t chan_id;
 
@@ -270,7 +270,7 @@ int lttng_session_enable(struct lttng_session *session)
                ctx = chan->ctx;
                if (ctx) {
                        nr_fields = ctx->nr_fields;
-                       fields = &ctx->fields->event_field;
+                       fields = ctx->fields;
                }
                ret = ustcomm_register_channel(notify_socket,
                        session->objd,
This page took 0.027782 seconds and 4 git commands to generate.