Send extended channel payload to client
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 7 Mar 2016 23:22:56 +0000 (18:22 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 7 Mar 2016 23:47:22 +0000 (18:47 -0500)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/main.c
src/lib/lttng-ctl/lttng-ctl.c

index ee80023fae3710e71bb790d7d81a4fddaf746360..87c6eb36dd2c6264848b021f772dddfe85abd0d5 100644 (file)
@@ -2839,8 +2839,7 @@ error:
 ssize_t cmd_list_channels(enum lttng_domain_type domain,
                struct ltt_session *session, struct lttng_channel **channels)
 {
-       int ret;
-       ssize_t nb_chan = 0;
+       ssize_t nb_chan = 0, payload_size = 0, ret;
 
        switch (domain) {
        case LTTNG_DOMAIN_KERNEL:
@@ -2849,7 +2848,8 @@ ssize_t cmd_list_channels(enum lttng_domain_type domain,
                }
                DBG3("Number of kernel channels %zd", nb_chan);
                if (nb_chan <= 0) {
-                       ret = LTTNG_ERR_KERN_CHAN_NOT_FOUND;
+                       ret = -LTTNG_ERR_KERN_CHAN_NOT_FOUND;
+                       goto end;
                }
                break;
        case LTTNG_DOMAIN_UST:
@@ -2861,30 +2861,37 @@ ssize_t cmd_list_channels(enum lttng_domain_type domain,
                }
                DBG3("Number of UST global channels %zd", nb_chan);
                if (nb_chan < 0) {
-                       ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
-                       goto error;
+                       ret = -LTTNG_ERR_UST_CHAN_NOT_FOUND;
+                       goto end;
                }
                break;
        default:
-               ret = LTTNG_ERR_UND;
-               goto error;
+               ret = -LTTNG_ERR_UND;
+               goto end;
        }
 
        if (nb_chan > 0) {
-               *channels = zmalloc(nb_chan * sizeof(struct lttng_channel));
+               const size_t channel_size = sizeof(struct lttng_channel) +
+                       sizeof(struct lttcomm_channel_extended);
+               struct lttcomm_channel_extended *channel_exts;
+
+               payload_size = nb_chan * channel_size;
+               *channels = zmalloc(payload_size);
                if (*channels == NULL) {
-                       ret = LTTNG_ERR_FATAL;
-                       goto error;
+                       ret = -LTTNG_ERR_FATAL;
+                       goto end;
                }
 
-               list_lttng_channels(domain, session, *channels);
+               channel_exts = ((void *) *channels) +
+                               (nb_chan * sizeof(struct lttng_channel));
+               list_lttng_channels(domain, session, *channels, channel_exts);
+       } else {
+               *channels = NULL;
        }
 
-       return nb_chan;
-
-error:
-       /* Return negative value to differentiate return code */
-       return -ret;
+       ret = payload_size;
+end:
+       return ret;
 }
 
 /*
index 72232122c7a6c2a875124ec569e9b03f7ac9544f..3f3ce4f1493dba040fdae3f1f8a140d5de2338d7 100644 (file)
@@ -3844,19 +3844,19 @@ error_add_context:
        }
        case LTTNG_LIST_CHANNELS:
        {
-               int nb_chan;
+               ssize_t payload_size;
                struct lttng_channel *channels = NULL;
 
-               nb_chan = cmd_list_channels(cmd_ctx->lsm->domain.type,
+               payload_size = cmd_list_channels(cmd_ctx->lsm->domain.type,
                                cmd_ctx->session, &channels);
-               if (nb_chan < 0) {
+               if (payload_size < 0) {
                        /* Return value is a negative lttng_error_code. */
-                       ret = -nb_chan;
+                       ret = -payload_size;
                        goto error;
                }
 
                ret = setup_lttng_msg_no_cmd_header(cmd_ctx, channels,
-                       nb_chan * sizeof(struct lttng_channel));
+                       payload_size);
                free(channels);
 
                if (ret < 0) {
index 6c10c910d8207be651e41e7c720be9a679e1972c..157d9a4335af5b5d52b3fcc7be942b4f2d77719a 100644 (file)
@@ -1694,10 +1694,15 @@ int lttng_list_channels(struct lttng_handle *handle,
                struct lttng_channel **channels)
 {
        int ret;
+       size_t channel_count, i;
+       const size_t channel_size = sizeof(struct lttng_channel) +
+                       sizeof(struct lttcomm_channel_extended);
        struct lttcomm_session_msg lsm;
+       void *extended_at;
 
        if (handle == NULL) {
-               return -LTTNG_ERR_INVALID;
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
        }
 
        memset(&lsm, 0, sizeof(lsm));
@@ -1709,10 +1714,30 @@ int lttng_list_channels(struct lttng_handle *handle,
 
        ret = lttng_ctl_ask_sessiond(&lsm, (void**) channels);
        if (ret < 0) {
-               return ret;
+               goto end;
        }
 
-       return ret / sizeof(struct lttng_channel);
+       if (ret % channel_size) {
+               ret = -LTTNG_ERR_UNK;
+               free(*channels);
+               *channels = NULL;
+               goto end;
+       }
+       channel_count = (size_t) ret / channel_size;
+
+       /* Set extended info pointers */
+       extended_at = ((void *) *channels) +
+                       channel_count * sizeof(struct lttng_channel);
+       for (i = 0; i < channel_count; i++) {
+               struct lttng_channel *chan = &(*channels)[i];
+
+               chan->attr.extended.ptr = extended_at;
+               extended_at += sizeof(struct lttcomm_channel_extended);
+       }
+
+       ret = (int) channel_count;
+end:
+       return ret;
 }
 
 /*
This page took 0.037526 seconds and 4 git commands to generate.