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:
}
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:
}
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;
}
/*
}
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) {
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));
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;
}
/*