#include <common/utils.h>
#include <lttng/lttng.h>
#include <lttng/health-internal.h>
+#include <lttng/trigger/trigger-internal.h>
+#include <lttng/endpoint.h>
+#include <lttng/channel-internal.h>
#include "filter/filter-ast.h"
#include "filter/filter-parser.h"
{
struct lttng_handle *handle = NULL;
- if (domain == NULL) {
- goto end;
- }
-
handle = zmalloc(sizeof(struct lttng_handle));
if (handle == NULL) {
PERROR("malloc handle");
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;
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:
* 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;
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;
}
/*
{
int ret;
struct lttcomm_session_msg lsm;
+ struct lttcomm_event_command_header *cmd_header = NULL;
+ size_t cmd_header_len;
+ uint32_t nb_events, i;
+ void *extended_at;
/* Safety check. An handle and channel name are mandatory */
if (handle == NULL || channel_name == NULL) {
sizeof(lsm.session.name));
lttng_ctl_copy_string(lsm.u.list.channel_name, channel_name,
sizeof(lsm.u.list.channel_name));
-
lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
- ret = lttng_ctl_ask_sessiond(&lsm, (void**) events);
+ ret = lttng_ctl_ask_sessiond_varlen(&lsm, NULL, 0, (void **) events,
+ (void **) &cmd_header, &cmd_header_len);
if (ret < 0) {
- return ret;
+ goto error;
}
- return ret / sizeof(struct lttng_event);
+ /* Set number of events and free command header */
+ nb_events = cmd_header->nb_events;
+ if (nb_events > INT_MAX) {
+ ret = -EOVERFLOW;
+ goto error;
+ }
+ ret = (int) nb_events;
+ free(cmd_header);
+ cmd_header = NULL;
+
+ /* Set extended info pointers */
+ extended_at = ((void*) (*events)) +
+ nb_events * sizeof(struct lttng_event);
+
+ for (i = 0; i < nb_events; i++) {
+ struct lttcomm_event_extended_header *ext_header;
+ struct lttng_event *event = &(*events)[i];
+
+ event->extended.ptr = extended_at;
+ ext_header =
+ (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;
+error:
+ free(cmd_header);
+ free(*events);
+ 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;
}
/*
return 0;
}
-/*
- * Returns size of returned session payload data or a negative error code.
- */
int lttng_calibrate(struct lttng_handle *handle,
struct lttng_calibrate *calibrate)
{
- struct lttcomm_session_msg lsm;
-
- /* Safety check. NULL pointer are forbidden */
- if (handle == NULL || calibrate == NULL) {
- return -LTTNG_ERR_INVALID;
- }
-
- memset(&lsm, 0, sizeof(lsm));
- lsm.cmd_type = LTTNG_CALIBRATE;
- lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
-
- memcpy(&lsm.u.calibrate, calibrate, sizeof(lsm.u.calibrate));
-
- return lttng_ctl_ask_sessiond(&lsm, NULL);
+ /*
+ * This command was removed in LTTng 2.9.
+ */
+ return -LTTNG_ERR_UND;
}
/*
}
}
+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.
*
return 0;
}
+/*
+ * Regenerate the metadata for a session.
+ * Return 0 on success, a negative error code on error.
+ */
+int lttng_regenerate_metadata(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_REGENERATE_METADATA;
+
+ 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;
+}
+
+/*
+ * Deprecated, replaced by lttng_regenerate_metadata.
+ */
+int lttng_metadata_regenerate(const char *session_name)
+{
+ return lttng_regenerate_metadata(session_name);
+}
+
+/*
+ * Regenerate the statedump of a session.
+ * Return 0 on success, a negative error code on error.
+ */
+int lttng_regenerate_statedump(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_REGENERATE_STATEDUMP;
+
+ 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;
+}
+
+int lttng_register_trigger(struct lttng_trigger *trigger)
+{
+ int ret;
+ struct lttcomm_session_msg lsm;
+ char *trigger_buf = NULL;
+ ssize_t trigger_size;
+
+ if (!trigger) {
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ if (!lttng_trigger_validate(trigger)) {
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ trigger_size = lttng_trigger_serialize(trigger, NULL);
+ if (trigger_size < 0) {
+ ret = -LTTNG_ERR_UNK;
+ goto end;
+ }
+
+ trigger_buf = zmalloc(trigger_size);
+ if (!trigger_buf) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ memset(&lsm, 0, sizeof(lsm));
+ lsm.cmd_type = LTTNG_REGISTER_TRIGGER;
+ if (lttng_trigger_serialize(trigger, trigger_buf) < 0) {
+ ret = -LTTNG_ERR_UNK;
+ goto end;
+ }
+
+ lsm.u.trigger.length = (uint32_t) trigger_size;
+ ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, trigger_buf,
+ trigger_size, NULL);
+end:
+ free(trigger_buf);
+ return ret;
+}
+
+int lttng_unregister_trigger(struct lttng_trigger *trigger)
+{
+ int ret;
+ struct lttcomm_session_msg lsm;
+ char *trigger_buf = NULL;
+ ssize_t trigger_size;
+
+ if (!trigger) {
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ if (!lttng_trigger_validate(trigger)) {
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ trigger_size = lttng_trigger_serialize(trigger, NULL);
+ if (trigger_size < 0) {
+ ret = -LTTNG_ERR_UNK;
+ goto end;
+ }
+
+ trigger_buf = zmalloc(trigger_size);
+ if (!trigger_buf) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ memset(&lsm, 0, sizeof(lsm));
+ lsm.cmd_type = LTTNG_UNREGISTER_TRIGGER;
+ if (lttng_trigger_serialize(trigger, trigger_buf) < 0) {
+ ret = -LTTNG_ERR_UNK;
+ goto end;
+ }
+
+ lsm.u.trigger.length = (uint32_t) trigger_size;
+ ret = lttng_ctl_ask_sessiond_varlen_no_cmd_header(&lsm, trigger_buf,
+ trigger_size, NULL);
+end:
+ free(trigger_buf);
+ return ret;
+}
+
/*
* lib constructor.
*/
-static void __attribute__((constructor)) init()
+static void __attribute__((constructor)) init(void)
{
/* Set default session group */
lttng_set_tracing_group(DEFAULT_TRACING_GROUP);
/*
* lib destructor.
*/
-static void __attribute__((destructor)) lttng_ctl_exit()
+static void __attribute__((destructor)) lttng_ctl_exit(void)
{
free(tracing_group);
}