X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Flib%2Flttng-ctl%2Flttng-ctl.c;h=d0deade2e5b2d0216c5012153d7b587b744ae9eb;hp=9cb2eb4a695648bfb3f4002248ffdeae3a6d6d64;hb=62a7b8edf965b89d3ca57da120dcedfcf36dfe02;hpb=b4e3ceb9d379829bc5d6ec799f83086317aeafd8 diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 9cb2eb4a6..d0deade2e 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -519,10 +519,6 @@ struct lttng_handle *lttng_create_handle(const char *session_name, { struct lttng_handle *handle = NULL; - if (domain == NULL) { - goto end; - } - handle = zmalloc(sizeof(struct lttng_handle)); if (handle == NULL) { PERROR("malloc handle"); @@ -533,8 +529,10 @@ struct lttng_handle *lttng_create_handle(const char *session_name, lttng_ctl_copy_string(handle->session_name, session_name, sizeof(handle->session_name)); - /* Copy lttng domain */ - lttng_ctl_copy_lttng_domain(&handle->domain, domain); + /* Copy lttng domain or leave initialized to 0. */ + if (domain) { + lttng_ctl_copy_lttng_domain(&handle->domain, domain); + } end: return handle; @@ -736,9 +734,16 @@ int lttng_add_context(struct lttng_handle *handle, memcpy(buf + provider_len, ctx_name, ctx_len); } memcpy(&lsm.u.context.ctx, ctx, sizeof(struct lttng_event_context)); - /* Don't leak application addresses to the sessiond. */ - lsm.u.context.ctx.u.app_ctx.provider_name = NULL; - lsm.u.context.ctx.u.app_ctx.ctx_name = NULL; + + if (ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT) { + /* + * Don't leak application addresses to the sessiond. + * This is only necessary when ctx is for an app ctx otherwise + * the values inside the union (type & config) are overwritten. + */ + lsm.u.context.ctx.u.app_ctx.provider_name = NULL; + lsm.u.context.ctx.u.app_ctx.ctx_name = NULL; + } ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, buf, len, NULL); end: @@ -1554,6 +1559,7 @@ int lttng_create_session(const char *name, const char *url) * Destroy session using name. * Returns size of returned session payload data or a negative error code. */ +static int _lttng_destroy_session(const char *session_name) { struct lttcomm_session_msg lsm; @@ -1694,10 +1700,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 +1720,30 @@ int lttng_list_channels(struct lttng_handle *handle, ret = lttng_ctl_ask_sessiond(&lsm, (void**) channels); if (ret < 0) { - return ret; + goto end; + } + + if (ret % channel_size) { + ret = -LTTNG_ERR_UNK; + free(*channels); + *channels = NULL; + goto end; } + channel_count = (size_t) ret / channel_size; - return ret / sizeof(struct lttng_channel); + /* 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; } /* @@ -1773,6 +1804,8 @@ int lttng_list_events(struct lttng_handle *handle, (struct lttcomm_event_extended_header *) extended_at; extended_at += sizeof(*ext_header); extended_at += ext_header->filter_len; + extended_at += + ext_header->nb_exclusions * LTTNG_SYMBOL_NAME_LEN; } return ret; @@ -1782,6 +1815,99 @@ error: return ret; } +int lttng_event_get_filter_expression(struct lttng_event *event, + const char **filter_expression) +{ + int ret = 0; + struct lttcomm_event_extended_header *ext_header; + + if (!event || !filter_expression) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + ext_header = event->extended.ptr; + + if (!ext_header) { + /* + * This can happen since the lttng_event structure is + * used for other tasks where this pointer is never set. + */ + *filter_expression = NULL; + goto end; + } + + if (ext_header->filter_len) { + *filter_expression = ((const char *) (ext_header)) + + sizeof(*ext_header); + } else { + *filter_expression = NULL; + } + +end: + return ret; +} + +int lttng_event_get_exclusion_name_count(struct lttng_event *event) +{ + int ret; + struct lttcomm_event_extended_header *ext_header; + + if (!event) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + ext_header = event->extended.ptr; + if (!ext_header) { + /* + * This can happen since the lttng_event structure is + * used for other tasks where this pointer is never set. + */ + ret = 0; + goto end; + } + + if (ext_header->nb_exclusions > INT_MAX) { + ret = -LTTNG_ERR_OVERFLOW; + goto end; + } + ret = (int) ext_header->nb_exclusions; +end: + return ret; +} + +int lttng_event_get_exclusion_name(struct lttng_event *event, + size_t index, const char **exclusion_name) +{ + int ret = 0; + struct lttcomm_event_extended_header *ext_header; + void *at; + + if (!event || !exclusion_name) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + ext_header = event->extended.ptr; + if (!ext_header) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + if (index >= ext_header->nb_exclusions) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + at = (void *) ext_header + sizeof(*ext_header); + at += ext_header->filter_len; + at += index * LTTNG_SYMBOL_NAME_LEN; + *exclusion_name = at; + +end: + return ret; +} /* * Sets the tracing_group variable with name. @@ -1879,6 +2005,58 @@ void lttng_channel_set_default_attr(struct lttng_domain *domain, } } +int lttng_channel_get_discarded_event_count(struct lttng_channel *channel, + uint64_t *discarded_events) +{ + int ret = 0; + struct lttcomm_channel_extended *chan_ext; + + if (!channel || !discarded_events) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + chan_ext = channel->attr.extended.ptr; + if (!chan_ext) { + /* + * This can happen since the lttng_channel structure is + * used for other tasks where this pointer is never set. + */ + *discarded_events = 0; + goto end; + } + + *discarded_events = chan_ext->discarded_events; +end: + return ret; +} + +int lttng_channel_get_lost_packet_count(struct lttng_channel *channel, + uint64_t *lost_packets) +{ + int ret = 0; + struct lttcomm_channel_extended *chan_ext; + + if (!channel || !lost_packets) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + chan_ext = channel->attr.extended.ptr; + if (!chan_ext) { + /* + * This can happen since the lttng_channel structure is + * used for other tasks where this pointer is never set. + */ + *lost_packets = 0; + goto end; + } + + *lost_packets = chan_ext->lost_packets; +end: + return ret; +} + /* * Check if session daemon is alive. * @@ -2202,6 +2380,36 @@ int lttng_list_tracker_pids(struct lttng_handle *handle, return 0; } +/* + * Regenerate the metadata for a session. + * Return 0 on success, a negative error code on error. + */ +int lttng_metadata_regenerate(const char *session_name) +{ + int ret; + struct lttcomm_session_msg lsm; + + if (!session_name) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + memset(&lsm, 0, sizeof(lsm)); + lsm.cmd_type = LTTNG_METADATA_REGENERATE; + + lttng_ctl_copy_string(lsm.session.name, session_name, + sizeof(lsm.session.name)); + + ret = lttng_ctl_ask_sessiond(&lsm, NULL); + if (ret < 0) { + goto end; + } + + ret = 0; +end: + return ret; +} + /* * lib constructor. */