*
*/
-#include "bin/lttng-sessiond/tracker.h"
-#include "lttng/lttng-error.h"
-#include "lttng/tracker.h"
+
#define _LGPL_SOURCE
#include <assert.h>
#include <inttypes.h>
+#include <stdio.h>
+#include <sys/stat.h>
#include <urcu/list.h>
#include <urcu/uatomic.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <common/defaults.h>
+#include <common/buffer-view.h>
#include <common/common.h>
-#include <common/sessiond-comm/sessiond-comm.h>
-#include <common/relayd/relayd.h>
-#include <common/utils.h>
#include <common/compat/string.h>
-#include <common/kernel-ctl/kernel-ctl.h>
+#include <common/defaults.h>
#include <common/dynamic-buffer.h>
-#include <common/buffer-view.h>
-#include <common/payload.h>
-#include <common/payload-view.h>
+#include <common/kernel-ctl/kernel-ctl.h>
+#include <common/relayd/relayd.h>
+#include <common/sessiond-comm/sessiond-comm.h>
+#include <common/string-utils/string-utils.h>
#include <common/trace-chunk.h>
-#include <lttng/location-internal.h>
-#include <lttng/trigger/trigger-internal.h>
-#include <lttng/condition/condition.h>
+#include <common/utils.h>
+
#include <lttng/action/action.h>
-#include <lttng/channel.h>
+#include <lttng/action/action-internal.h>
#include <lttng/channel-internal.h>
-#include <lttng/rotate-internal.h>
+#include <lttng/channel.h>
+#include <lttng/condition/condition.h>
+#include <lttng/error-query-internal.h>
+#include <lttng/event-internal.h>
#include <lttng/location-internal.h>
+#include <lttng/rotate-internal.h>
+#include <lttng/session-descriptor-internal.h>
#include <lttng/session-internal.h>
+#include <lttng/trigger/trigger-internal.h>
#include <lttng/userspace-probe-internal.h>
-#include <lttng/session-descriptor-internal.h>
-#include <common/string-utils/string-utils.h>
+#include "agent-thread.h"
+#include "agent.h"
+#include "buffer-registry.h"
#include "channel.h"
+#include "cmd.h"
#include "consumer.h"
+#include "event-notifier-error-accounting.h"
#include "event.h"
#include "health-sessiond.h"
-#include "kernel.h"
#include "kernel-consumer.h"
+#include "kernel.h"
#include "lttng-sessiond.h"
-#include "utils.h"
#include "lttng-syscall.h"
-#include "agent.h"
-#include "buffer-registry.h"
-#include "notification-thread.h"
#include "notification-thread-commands.h"
+#include "notification-thread.h"
#include "rotate.h"
#include "rotation-thread.h"
+#include "session.h"
#include "timer.h"
-#include "agent-thread.h"
-
-#include "cmd.h"
+#include "tracker.h"
+#include "utils.h"
/* Sleep for 100ms between each check for the shm path's deletion. */
#define SESSION_DESTROY_SHM_PATH_CHECK_DELAY_US 100000
const struct lttng_domain *domain,
char *channel_name, struct lttng_event *event,
char *filter_expression,
- struct lttng_filter_bytecode *filter,
+ struct lttng_bytecode *filter,
struct lttng_event_exclusion *exclusion,
int wpipe);
+static int cmd_enable_channel_internal(struct ltt_session *session,
+ const struct lttng_domain *domain,
+ const struct lttng_channel *_attr,
+ int wpipe);
/*
* Create a session path used by list_lttng_sessions for the case that the
}
/*
- * Fill lttng_channel array of all channels.
+ * Create a list of agent domain events.
+ *
+ * Return number of events in list on success or else a negative value.
*/
-static ssize_t list_lttng_channels(enum lttng_domain_type domain,
- struct ltt_session *session, struct lttng_channel *channels,
- struct lttng_channel_extended *chan_exts)
+static enum lttng_error_code list_lttng_agent_events(
+ struct agent *agt, struct lttng_payload *reply_payload,
+ unsigned int *nb_events)
{
- int i = 0, ret = 0;
- struct ltt_kernel_channel *kchan;
-
- DBG("Listing channels for session %s", session->name);
-
- switch (domain) {
- case LTTNG_DOMAIN_KERNEL:
- /* Kernel channels */
- if (session->kernel_session != NULL) {
- cds_list_for_each_entry(kchan,
- &session->kernel_session->channel_list.head, list) {
- uint64_t discarded_events, lost_packets;
- struct lttng_channel_extended *extended;
-
- extended = (struct lttng_channel_extended *)
- kchan->channel->attr.extended.ptr;
-
- ret = get_kernel_runtime_stats(session, kchan,
- &discarded_events, &lost_packets);
- if (ret < 0) {
- goto end;
- }
- /* Copy lttng_channel struct to array */
- memcpy(&channels[i], kchan->channel, sizeof(struct lttng_channel));
- channels[i].enabled = kchan->enabled;
- chan_exts[i].discarded_events =
- discarded_events;
- chan_exts[i].lost_packets = lost_packets;
- chan_exts[i].monitor_timer_interval =
- extended->monitor_timer_interval;
- chan_exts[i].blocking_timeout = 0;
- i++;
- }
- }
- break;
- case LTTNG_DOMAIN_UST:
- {
- struct lttng_ht_iter iter;
- struct ltt_ust_channel *uchan;
-
- rcu_read_lock();
- cds_lfht_for_each_entry(session->ust_session->domain_global.channels->ht,
- &iter.iter, uchan, node.node) {
- uint64_t discarded_events = 0, lost_packets = 0;
-
- if (lttng_strncpy(channels[i].name, uchan->name,
- LTTNG_SYMBOL_NAME_LEN)) {
- break;
- }
- channels[i].attr.overwrite = uchan->attr.overwrite;
- channels[i].attr.subbuf_size = uchan->attr.subbuf_size;
- channels[i].attr.num_subbuf = uchan->attr.num_subbuf;
- channels[i].attr.switch_timer_interval =
- uchan->attr.switch_timer_interval;
- channels[i].attr.read_timer_interval =
- uchan->attr.read_timer_interval;
- channels[i].enabled = uchan->enabled;
- channels[i].attr.tracefile_size = uchan->tracefile_size;
- channels[i].attr.tracefile_count = uchan->tracefile_count;
-
- /*
- * Map enum lttng_ust_output to enum lttng_event_output.
- */
- switch (uchan->attr.output) {
- case LTTNG_UST_MMAP:
- channels[i].attr.output = LTTNG_EVENT_MMAP;
- break;
- default:
- /*
- * LTTNG_UST_MMAP is the only supported UST
- * output mode.
- */
- assert(0);
- break;
- }
+ enum lttng_error_code ret_code;
+ int ret = 0;
+ unsigned int local_nb_events = 0;
+ struct agent_event *event;
+ struct lttng_ht_iter iter;
+ unsigned long agent_event_count;
- chan_exts[i].monitor_timer_interval =
- uchan->monitor_timer_interval;
- chan_exts[i].blocking_timeout =
- uchan->attr.u.s.blocking_timeout;
+ assert(agt);
+ assert(reply_payload);
- ret = get_ust_runtime_stats(session, uchan,
- &discarded_events, &lost_packets);
- if (ret < 0) {
- break;
- }
- chan_exts[i].discarded_events = discarded_events;
- chan_exts[i].lost_packets = lost_packets;
- i++;
- }
- rcu_read_unlock();
- break;
- }
- default:
- break;
- }
+ DBG3("Listing agent events");
-end:
- if (ret < 0) {
- return -LTTNG_ERR_FATAL;
- } else {
- return LTTNG_OK;
- }
-}
+ rcu_read_lock();
-static int append_extended_info(const char *filter_expression,
- struct lttng_event_exclusion *exclusion,
- struct lttng_userspace_probe_location *probe_location,
- struct lttng_payload *payload)
-{
- int ret = 0;
- size_t filter_len = 0;
- size_t nb_exclusions = 0;
- size_t userspace_probe_location_len = 0;
- struct lttcomm_event_extended_header extended_header = {};
- struct lttcomm_event_extended_header *p_extended_header;
- const size_t original_payload_size = payload->buffer.size;
-
- ret = lttng_dynamic_buffer_append(&payload->buffer, &extended_header,
- sizeof(extended_header));
- if (ret) {
+ agent_event_count = lttng_ht_get_count(agt->events);
+ if (agent_event_count == 0) {
+ /* Early exit. */
goto end;
}
- if (filter_expression) {
- filter_len = strlen(filter_expression) + 1;
- ret = lttng_dynamic_buffer_append(&payload->buffer,
- filter_expression, filter_len);
- if (ret) {
- goto end;
- }
+ if (agent_event_count > UINT_MAX) {
+ ret_code = LTTNG_ERR_OVERFLOW;
+ goto error;
}
- if (exclusion) {
- const size_t len = exclusion->count * LTTNG_SYMBOL_NAME_LEN;
+ local_nb_events = (unsigned int) agent_event_count;
- nb_exclusions = exclusion->count;
+ cds_lfht_for_each_entry(agt->events->ht, &iter.iter, event, node.node) {
+ struct lttng_event *tmp_event = lttng_event_create();
- ret = lttng_dynamic_buffer_append(
- &payload->buffer, &exclusion->names, len);
- if (ret) {
- goto end;
+ if (!tmp_event) {
+ ret_code = LTTNG_ERR_NOMEM;
+ goto error;
}
- }
- if (probe_location) {
- const size_t size_before_probe = payload->buffer.size;
-
- ret = lttng_userspace_probe_location_serialize(probe_location,
- payload);
- if (ret < 0) {
- ret = -1;
- goto end;
+ if (lttng_strncpy(tmp_event->name, event->name, sizeof(tmp_event->name))) {
+ lttng_event_destroy(tmp_event);
+ ret_code = LTTNG_ERR_FATAL;
+ goto error;
}
+
+ tmp_event->name[sizeof(tmp_event->name) - 1] = '\0';
+ tmp_event->enabled = !!event->enabled_count;
+ tmp_event->loglevel = event->loglevel_value;
+ tmp_event->loglevel_type = event->loglevel_type;
- userspace_probe_location_len =
- payload->buffer.size - size_before_probe;
- }
-
- /* Set header fields */
- p_extended_header = (struct lttcomm_event_extended_header *)
- (payload->buffer.data + original_payload_size);
-
- p_extended_header->filter_len = filter_len;
- p_extended_header->nb_exclusions = nb_exclusions;
- p_extended_header->userspace_probe_location_len =
- userspace_probe_location_len;
-
- ret = 0;
-end:
- return ret;
-}
-
-/*
- * Create a list of agent domain events.
- *
- * Return number of events in list on success or else a negative value.
- */
-static int list_lttng_agent_events(struct agent *agt,
- struct lttng_payload *payload)
-{
- int nb_events = 0, ret = 0;
- const struct agent_event *agent_event;
- struct lttng_ht_iter iter;
-
- assert(agt);
-
- DBG3("Listing agent events");
-
- rcu_read_lock();
- cds_lfht_for_each_entry (
- agt->events->ht, &iter.iter, agent_event, node.node) {
- struct lttng_event event = {
- .enabled = agent_event->enabled,
- .loglevel = agent_event->loglevel_value,
- .loglevel_type = agent_event->loglevel_type,
- };
-
- strncpy(event.name, agent_event->name, sizeof(event.name));
- event.name[sizeof(event.name) - 1] = '\0';
-
- ret = lttng_dynamic_buffer_append(
- &payload->buffer, &event, sizeof(event));
+ ret = lttng_event_serialize(tmp_event, 0, NULL,
+ event->filter_expression, 0, NULL, reply_payload);
+ lttng_event_destroy(tmp_event);
if (ret) {
- ERR("Failed to append event to payload");
- ret = -LTTNG_ERR_NOMEM;
- goto end;
- }
-
- nb_events++;
- }
-
- cds_lfht_for_each_entry (
- agt->events->ht, &iter.iter, agent_event, node.node) {
- /* Append extended info. */
- ret = append_extended_info(agent_event->filter_expression, NULL,
- NULL, payload);
- if (ret) {
- ERR("Failed to append extended event info to payload");
- ret = -LTTNG_ERR_NOMEM;
- goto end;
+ ret_code = LTTNG_ERR_FATAL;
+ goto error;
}
}
- ret = nb_events;
end:
+ ret_code = LTTNG_OK;
+ *nb_events = local_nb_events;
+error:
rcu_read_unlock();
- return ret;
+ return ret_code;
}
/*
* Create a list of ust global domain events.
*/
-static int list_lttng_ust_global_events(char *channel_name,
+static enum lttng_error_code list_lttng_ust_global_events(char *channel_name,
struct ltt_ust_domain_global *ust_global,
- struct lttng_payload *payload)
+ struct lttng_payload *reply_payload,
+ unsigned int *nb_events)
{
- int ret = 0;
- unsigned int nb_events = 0;
+ enum lttng_error_code ret_code;
+ int ret;
struct lttng_ht_iter iter;
- const struct lttng_ht_node_str *node;
- const struct ltt_ust_channel *uchan;
- const struct ltt_ust_event *uevent;
+ struct lttng_ht_node_str *node;
+ struct ltt_ust_channel *uchan;
+ struct ltt_ust_event *uevent;
+ unsigned long channel_event_count;
+ unsigned int local_nb_events = 0;
+
+ assert(reply_payload);
+ assert(nb_events);
DBG("Listing UST global events for channel %s", channel_name);
lttng_ht_lookup(ust_global->channels, (void *) channel_name, &iter);
node = lttng_ht_iter_get_node_str(&iter);
if (node == NULL) {
- ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
+ ret_code = LTTNG_ERR_UST_CHAN_NOT_FOUND;
goto end;
}
uchan = caa_container_of(&node->node, struct ltt_ust_channel, node.node);
- DBG3("Listing UST global events");
+ channel_event_count = lttng_ht_get_count(uchan->events);
+ if (channel_event_count == 0) {
+ /* Early exit. */
+ ret_code = LTTNG_OK;
+ goto end;
+ }
+
+ if (channel_event_count > UINT_MAX) {
+ ret_code = LTTNG_ERR_OVERFLOW;
+ goto error;
+ }
+
+ local_nb_events = (unsigned int) channel_event_count;
+
+ DBG3("Listing UST global %d events", *nb_events);
cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent, node.node) {
- struct lttng_event event = {};
+ struct lttng_event *tmp_event = NULL;
if (uevent->internal) {
+ /* This event should remain hidden from clients */
+ local_nb_events--;
continue;
}
- strncpy(event.name, uevent->attr.name, sizeof(event.name));
- event.name[sizeof(event.name) - 1] = '\0';
+ tmp_event = lttng_event_create();
+ if (!tmp_event) {
+ ret_code = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ if (lttng_strncpy(tmp_event->name, uevent->attr.name,
+ LTTNG_SYMBOL_NAME_LEN)) {
+ ret_code = LTTNG_ERR_FATAL;
+ lttng_event_destroy(tmp_event);
+ goto end;
+ }
- event.enabled = uevent->enabled;
+ tmp_event->name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
+ tmp_event->enabled = uevent->enabled;
switch (uevent->attr.instrumentation) {
- case LTTNG_UST_TRACEPOINT:
- event.type = LTTNG_EVENT_TRACEPOINT;
+ case LTTNG_UST_ABI_TRACEPOINT:
+ tmp_event->type = LTTNG_EVENT_TRACEPOINT;
break;
- case LTTNG_UST_PROBE:
- event.type = LTTNG_EVENT_PROBE;
+ case LTTNG_UST_ABI_PROBE:
+ tmp_event->type = LTTNG_EVENT_PROBE;
break;
- case LTTNG_UST_FUNCTION:
- event.type = LTTNG_EVENT_FUNCTION;
+ case LTTNG_UST_ABI_FUNCTION:
+ tmp_event->type = LTTNG_EVENT_FUNCTION;
break;
}
- event.loglevel = uevent->attr.loglevel;
+ tmp_event->loglevel = uevent->attr.loglevel;
switch (uevent->attr.loglevel_type) {
- case LTTNG_UST_LOGLEVEL_ALL:
- event.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
+ case LTTNG_UST_ABI_LOGLEVEL_ALL:
+ tmp_event->loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
break;
- case LTTNG_UST_LOGLEVEL_RANGE:
- event.loglevel_type = LTTNG_EVENT_LOGLEVEL_RANGE;
+ case LTTNG_UST_ABI_LOGLEVEL_RANGE:
+ tmp_event->loglevel_type = LTTNG_EVENT_LOGLEVEL_RANGE;
break;
- case LTTNG_UST_LOGLEVEL_SINGLE:
- event.loglevel_type = LTTNG_EVENT_LOGLEVEL_SINGLE;
+ case LTTNG_UST_ABI_LOGLEVEL_SINGLE:
+ tmp_event->loglevel_type = LTTNG_EVENT_LOGLEVEL_SINGLE;
break;
}
-
if (uevent->filter) {
- event.filter = 1;
+ tmp_event->filter = 1;
}
-
if (uevent->exclusion) {
- event.exclusion = 1;
- }
-
- ret = lttng_dynamic_buffer_append(&payload->buffer, &event, sizeof(event));
- if (ret) {
- ERR("Failed to append event to payload");
- ret = -LTTNG_ERR_NOMEM;
- goto end;
+ tmp_event->exclusion = 1;
}
- nb_events++;
- }
-
- cds_lfht_for_each_entry(uchan->events->ht, &iter.iter, uevent, node.node) {
- /* Append extended info. */
- ret = append_extended_info(uevent->filter_expression,
- uevent->exclusion, NULL, payload);
+ /*
+ * We do not care about the filter bytecode and the fd from the
+ * userspace_probe_location.
+ */
+ ret = lttng_event_serialize(tmp_event, uevent->exclusion ? uevent->exclusion->count : 0,
+ uevent->exclusion ? (char **) uevent->exclusion ->names : NULL,
+ uevent->filter_expression, 0, NULL, reply_payload);
+ lttng_event_destroy(tmp_event);
if (ret) {
- ERR("Failed to append extended event info to payload");
- ret = -LTTNG_ERR_FATAL;
- goto end;
+ ret_code = LTTNG_ERR_FATAL;
+ goto error;
}
}
- ret = nb_events;
end:
+ /* nb_events is already set at this point. */
+ ret_code = LTTNG_OK;
+ *nb_events = local_nb_events;
+error:
rcu_read_unlock();
- return ret;
+ return ret_code;
}
/*
* Fill lttng_event array of all kernel events in the channel.
*/
-static int list_lttng_kernel_events(char *channel_name,
+static enum lttng_error_code list_lttng_kernel_events(char *channel_name,
struct ltt_kernel_session *kernel_session,
- struct lttng_payload *payload)
+ struct lttng_payload *reply_payload,
+ unsigned int *nb_events)
{
+ enum lttng_error_code ret_code;
int ret;
- unsigned int nb_event;
- const struct ltt_kernel_event *kevent;
- const struct ltt_kernel_channel *kchan;
+ struct ltt_kernel_event *event;
+ struct ltt_kernel_channel *kchan;
+
+ assert(reply_payload);
kchan = trace_kernel_get_channel_by_name(channel_name, kernel_session);
if (kchan == NULL) {
- ret = LTTNG_ERR_KERN_CHAN_NOT_FOUND;
- goto error;
+ ret_code = LTTNG_ERR_KERN_CHAN_NOT_FOUND;
+ goto end;
}
- nb_event = kchan->event_count;
+ *nb_events = kchan->event_count;
DBG("Listing events for channel %s", kchan->channel->name);
+ if (*nb_events == 0) {
+ ret_code = LTTNG_OK;
+ goto end;
+ }
+
/* Kernel channels */
- cds_list_for_each_entry(kevent, &kchan->events_list.head , list) {
- struct lttng_event event = {};
+ cds_list_for_each_entry(event, &kchan->events_list.head , list) {
+ struct lttng_event *tmp_event = lttng_event_create();
+
+ if (!tmp_event) {
+ ret_code = LTTNG_ERR_NOMEM;
+ goto end;
+ }
- strncpy(event.name, kevent->event->name, sizeof(event.name));
- event.name[sizeof(event.name) - 1] = '\0';
- event.enabled = kevent->enabled;
- event.filter = (unsigned char) !!kevent->filter_expression;
+ if (lttng_strncpy(tmp_event->name, event->event->name, LTTNG_SYMBOL_NAME_LEN)) {
+ lttng_event_destroy(tmp_event);
+ ret_code = LTTNG_ERR_FATAL;
+ goto end;
- switch (kevent->event->instrumentation) {
- case LTTNG_KERNEL_TRACEPOINT:
- event.type = LTTNG_EVENT_TRACEPOINT;
+ }
+
+ tmp_event->name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
+ tmp_event->enabled = event->enabled;
+ tmp_event->filter = (unsigned char) !!event->filter_expression;
+
+ switch (event->event->instrumentation) {
+ case LTTNG_KERNEL_ABI_TRACEPOINT:
+ tmp_event->type = LTTNG_EVENT_TRACEPOINT;
break;
- case LTTNG_KERNEL_KRETPROBE:
- event.type = LTTNG_EVENT_FUNCTION;
- memcpy(&event.attr.probe, &kevent->event->u.kprobe,
- sizeof(struct lttng_kernel_kprobe));
+ case LTTNG_KERNEL_ABI_KRETPROBE:
+ tmp_event->type = LTTNG_EVENT_FUNCTION;
+ memcpy(&tmp_event->attr.probe, &event->event->u.kprobe,
+ sizeof(struct lttng_kernel_abi_kprobe));
break;
- case LTTNG_KERNEL_KPROBE:
- event.type = LTTNG_EVENT_PROBE;
- memcpy(&event.attr.probe, &kevent->event->u.kprobe,
- sizeof(struct lttng_kernel_kprobe));
+ case LTTNG_KERNEL_ABI_KPROBE:
+ tmp_event->type = LTTNG_EVENT_PROBE;
+ memcpy(&tmp_event->attr.probe, &event->event->u.kprobe,
+ sizeof(struct lttng_kernel_abi_kprobe));
break;
- case LTTNG_KERNEL_UPROBE:
- event.type = LTTNG_EVENT_USERSPACE_PROBE;
+ case LTTNG_KERNEL_ABI_UPROBE:
+ tmp_event->type = LTTNG_EVENT_USERSPACE_PROBE;
break;
- case LTTNG_KERNEL_FUNCTION:
- event.type = LTTNG_EVENT_FUNCTION;
- memcpy(&event.attr.ftrace, &kevent->event->u.ftrace,
- sizeof(struct lttng_kernel_function));
+ case LTTNG_KERNEL_ABI_FUNCTION:
+ tmp_event->type = LTTNG_EVENT_FUNCTION;
+ memcpy(&(tmp_event->attr.ftrace), &event->event->u.ftrace,
+ sizeof(struct lttng_kernel_abi_function));
break;
- case LTTNG_KERNEL_NOOP:
- event.type = LTTNG_EVENT_NOOP;
+ case LTTNG_KERNEL_ABI_NOOP:
+ tmp_event->type = LTTNG_EVENT_NOOP;
break;
- case LTTNG_KERNEL_SYSCALL:
- event.type = LTTNG_EVENT_SYSCALL;
+ case LTTNG_KERNEL_ABI_SYSCALL:
+ tmp_event->type = LTTNG_EVENT_SYSCALL;
break;
- case LTTNG_KERNEL_ALL:
+ case LTTNG_KERNEL_ABI_ALL:
/* fall-through. */
default:
assert(0);
break;
}
- ret = lttng_dynamic_buffer_append(
- &payload->buffer, &event, sizeof(event));
- if (ret) {
- ERR("Failed to append event to payload");
- ret = -LTTNG_ERR_NOMEM;
- goto end;
+ if (event->userspace_probe_location) {
+ struct lttng_userspace_probe_location *location_copy =
+ lttng_userspace_probe_location_copy(
+ event->userspace_probe_location);
+
+ if (!location_copy) {
+ lttng_event_destroy(tmp_event);
+ ret_code = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ ret = lttng_event_set_userspace_probe_location(
+ tmp_event, location_copy);
+ if (ret) {
+ lttng_event_destroy(tmp_event);
+ lttng_userspace_probe_location_destroy(
+ location_copy);
+ ret_code = LTTNG_ERR_INVALID;
+ goto end;
+ }
}
- }
- cds_list_for_each_entry(kevent, &kchan->events_list.head , list) {
- /* Append extended info. */
- ret = append_extended_info(kevent->filter_expression, NULL,
- kevent->userspace_probe_location, payload);
+ ret = lttng_event_serialize(tmp_event, 0, NULL,
+ event->filter_expression, 0, NULL, reply_payload);
+ lttng_event_destroy(tmp_event);
if (ret) {
- DBG("Error appending extended info message");
- ret = -LTTNG_ERR_FATAL;
- goto error;
+ ret_code = LTTNG_ERR_FATAL;
+ goto end;
}
}
+ ret_code = LTTNG_OK;
end:
- return nb_event;
-error:
- return ret;
+ return ret_code;
}
/*
*
* The wpipe arguments is used as a notifier for the kernel thread.
*/
-int cmd_enable_channel(struct ltt_session *session,
- const struct lttng_domain *domain, const struct lttng_channel *_attr, int wpipe)
+int cmd_enable_channel(struct command_ctx *cmd_ctx, int sock, int wpipe)
+{
+ int ret;
+ size_t channel_len;
+ ssize_t sock_recv_len;
+ struct lttng_channel *channel = NULL;
+ struct lttng_buffer_view view;
+ struct lttng_dynamic_buffer channel_buffer;
+ const struct lttng_domain command_domain = cmd_ctx->lsm.domain;
+
+ lttng_dynamic_buffer_init(&channel_buffer);
+ channel_len = (size_t) cmd_ctx->lsm.u.channel.length;
+ ret = lttng_dynamic_buffer_set_size(&channel_buffer, channel_len);
+ if (ret) {
+ ret = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ sock_recv_len = lttcomm_recv_unix_sock(sock, channel_buffer.data,
+ channel_len);
+ if (sock_recv_len < 0 || sock_recv_len != channel_len) {
+ ERR("Failed to receive \"enable channel\" command payload");
+ ret = LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ view = lttng_buffer_view_from_dynamic_buffer(&channel_buffer, 0, channel_len);
+ if (!lttng_buffer_view_is_valid(&view)) {
+ ret = LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ if (lttng_channel_create_from_buffer(&view, &channel) != channel_len) {
+ ERR("Invalid channel payload received in \"enable channel\" command");
+ ret = LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+ ret = cmd_enable_channel_internal(
+ cmd_ctx->session, &command_domain, channel, wpipe);
+
+end:
+ lttng_dynamic_buffer_reset(&channel_buffer);
+ lttng_channel_destroy(channel);
+ return ret;
+}
+
+static int cmd_enable_channel_internal(struct ltt_session *session,
+ const struct lttng_domain *domain,
+ const struct lttng_channel *_attr,
+ int wpipe)
{
int ret;
struct ltt_ust_session *usess = session->ust_session;
struct lttng_ht *chan_ht;
size_t len;
- struct lttng_channel attr;
+ struct lttng_channel *attr = NULL;
assert(session);
assert(_attr);
assert(domain);
- attr = *_attr;
- len = lttng_strnlen(attr.name, sizeof(attr.name));
+ attr = lttng_channel_copy(_attr);
+ if (!attr) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ len = lttng_strnlen(attr->name, sizeof(attr->name));
/* Validate channel name */
- if (attr.name[0] == '.' ||
- memchr(attr.name, '/', len) != NULL) {
+ if (attr->name[0] == '.' ||
+ memchr(attr->name, '/', len) != NULL) {
ret = LTTNG_ERR_INVALID_CHANNEL_NAME;
goto end;
}
- DBG("Enabling channel %s for session %s", attr.name, session->name);
+ DBG("Enabling channel %s for session %s", attr->name, session->name);
rcu_read_lock();
- /*
- * Don't try to enable a channel if the session has been started at
- * some point in time before. The tracer does not allow it.
- */
- if (session->has_been_started) {
- ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
- goto error;
- }
-
/*
* If the session is a live session, remove the switch timer, the
* live timer does the same thing but sends also synchronisation
* beacons for inactive streams.
*/
if (session->live_timer > 0) {
- attr.attr.live_timer_interval = session->live_timer;
- attr.attr.switch_timer_interval = 0;
+ attr->attr.live_timer_interval = session->live_timer;
+ attr->attr.switch_timer_interval = 0;
}
/* Check for feature support */
WARN("Kernel tracer does not support buffer monitoring. "
"Setting the monitor interval timer to 0 "
"(disabled) for channel '%s' of session '%s'",
- attr.name, session->name);
- lttng_channel_set_monitor_timer_interval(&attr, 0);
+ attr->name, session->name);
+ lttng_channel_set_monitor_timer_interval(attr, 0);
}
break;
}
{
struct ltt_kernel_channel *kchan;
- kchan = trace_kernel_get_channel_by_name(attr.name,
- session->kernel_session);
+ kchan = trace_kernel_get_channel_by_name(
+ attr->name, session->kernel_session);
if (kchan == NULL) {
+ /*
+ * Don't try to create a channel if the session has been started at
+ * some point in time before. The tracer does not allow it.
+ */
+ if (session->has_been_started) {
+ ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
+ goto error;
+ }
+
if (session->snapshot.nb_output > 0 ||
session->snapshot_mode) {
/* Enforce mmap output for snapshot sessions. */
- attr.attr.output = LTTNG_EVENT_MMAP;
+ attr->attr.output = LTTNG_EVENT_MMAP;
}
- ret = channel_kernel_create(session->kernel_session, &attr, wpipe);
- if (attr.name[0] != '\0') {
+ ret = channel_kernel_create(
+ session->kernel_session, attr, wpipe);
+ if (attr->name[0] != '\0') {
session->kernel_session->has_non_default_channel = 1;
}
} else {
* adhered to.
*/
if (domain->type == LTTNG_DOMAIN_JUL) {
- if (strncmp(attr.name, DEFAULT_JUL_CHANNEL_NAME,
+ if (strncmp(attr->name, DEFAULT_JUL_CHANNEL_NAME,
LTTNG_SYMBOL_NAME_LEN)) {
ret = LTTNG_ERR_INVALID_CHANNEL_NAME;
goto error;
}
} else if (domain->type == LTTNG_DOMAIN_LOG4J) {
- if (strncmp(attr.name, DEFAULT_LOG4J_CHANNEL_NAME,
+ if (strncmp(attr->name, DEFAULT_LOG4J_CHANNEL_NAME,
LTTNG_SYMBOL_NAME_LEN)) {
ret = LTTNG_ERR_INVALID_CHANNEL_NAME;
goto error;
}
} else if (domain->type == LTTNG_DOMAIN_PYTHON) {
- if (strncmp(attr.name, DEFAULT_PYTHON_CHANNEL_NAME,
+ if (strncmp(attr->name, DEFAULT_PYTHON_CHANNEL_NAME,
LTTNG_SYMBOL_NAME_LEN)) {
ret = LTTNG_ERR_INVALID_CHANNEL_NAME;
goto error;
chan_ht = usess->domain_global.channels;
- uchan = trace_ust_find_channel_by_name(chan_ht, attr.name);
+ uchan = trace_ust_find_channel_by_name(chan_ht, attr->name);
if (uchan == NULL) {
- ret = channel_ust_create(usess, &attr, domain->buf_type);
- if (attr.name[0] != '\0') {
+ /*
+ * Don't try to create a channel if the session has been started at
+ * some point in time before. The tracer does not allow it.
+ */
+ if (session->has_been_started) {
+ ret = LTTNG_ERR_TRACE_ALREADY_STARTED;
+ goto error;
+ }
+
+ ret = channel_ust_create(usess, attr, domain->buf_type);
+ if (attr->name[0] != '\0') {
usess->has_non_default_channel = 1;
}
} else {
goto error;
}
- if (ret == LTTNG_OK && attr.attr.output != LTTNG_EVENT_MMAP) {
+ if (ret == LTTNG_OK && attr->attr.output != LTTNG_EVENT_MMAP) {
session->has_non_mmap_channel = true;
}
error:
rcu_read_unlock();
end:
+ lttng_channel_destroy(attr);
return ret;
}
/*
* Command LTTNG_DISABLE_EVENT processed by the client thread.
*/
-int cmd_disable_event(struct ltt_session *session,
- enum lttng_domain_type domain, const char *channel_name,
- const struct lttng_event *event)
+int cmd_disable_event(struct command_ctx *cmd_ctx,
+ struct lttng_event *event,
+ char *filter_expression,
+ struct lttng_bytecode *bytecode,
+ struct lttng_event_exclusion *exclusion)
{
int ret;
const char *event_name;
+ const struct ltt_session *session = cmd_ctx->session;
+ const char *channel_name = cmd_ctx->lsm.u.disable.channel_name;
+ const enum lttng_domain_type domain = cmd_ctx->lsm.domain.type;
DBG("Disable event command for event \'%s\'", event->name);
+ /*
+ * Filter and exclusions are simply not handled by the
+ * disable event command at this time.
+ *
+ * FIXME
+ */
+ (void) filter_expression;
+ (void) exclusion;
+
+ /* Ignore the presence of filter or exclusion for the event */
+ event->filter = 0;
+ event->exclusion = 0;
+
event_name = event->name;
/* Error out on unhandled search criteria */
error_unlock:
rcu_read_unlock();
error:
+ free(exclusion);
+ free(bytecode);
+ free(filter_expression);
return ret;
}
const struct lttng_domain *domain,
char *channel_name, struct lttng_event *event,
char *filter_expression,
- struct lttng_filter_bytecode *filter,
+ struct lttng_bytecode *filter,
struct lttng_event_exclusion *exclusion,
int wpipe, bool internal_event)
{
goto error;
}
- ret = cmd_enable_channel(session, domain, attr, wpipe);
+ ret = cmd_enable_channel_internal(
+ session, domain, attr, wpipe);
if (ret != LTTNG_OK) {
goto error;
}
case LTTNG_EVENT_ALL:
{
char *filter_expression_a = NULL;
- struct lttng_filter_bytecode *filter_a = NULL;
+ struct lttng_bytecode *filter_a = NULL;
/*
* We need to duplicate filter_expression and filter,
goto error;
}
- ret = cmd_enable_channel(session, domain, attr, wpipe);
+ ret = cmd_enable_channel_internal(
+ session, domain, attr, wpipe);
if (ret != LTTNG_OK) {
goto error;
}
{
char *filter_expression_copy = NULL;
- struct lttng_filter_bytecode *filter_copy = NULL;
+ struct lttng_bytecode *filter_copy = NULL;
if (filter) {
const size_t filter_size = sizeof(
- struct lttng_filter_bytecode)
+ struct lttng_bytecode)
+ filter->len;
filter_copy = zmalloc(filter_size);
* Command LTTNG_ENABLE_EVENT processed by the client thread.
* We own filter, exclusion, and filter_expression.
*/
-int cmd_enable_event(struct ltt_session *session,
- const struct lttng_domain *domain,
- char *channel_name, struct lttng_event *event,
+int cmd_enable_event(struct command_ctx *cmd_ctx,
+ struct lttng_event *event,
char *filter_expression,
- struct lttng_filter_bytecode *filter,
struct lttng_event_exclusion *exclusion,
+ struct lttng_bytecode *bytecode,
int wpipe)
{
- return _cmd_enable_event(session, domain, channel_name, event,
- filter_expression, filter, exclusion, wpipe, false);
+ int ret;
+ /*
+ * Copied to ensure proper alignment since 'lsm' is a packed structure.
+ */
+ const struct lttng_domain command_domain = cmd_ctx->lsm.domain;
+
+ /*
+ * The ownership of the following parameters is transferred to
+ * _cmd_enable_event:
+ *
+ * - filter_expression,
+ * - bytecode,
+ * - exclusion
+ */
+ ret = _cmd_enable_event(cmd_ctx->session,
+ &command_domain,
+ cmd_ctx->lsm.u.enable.channel_name, event,
+ filter_expression, bytecode, exclusion, wpipe, false);
+ filter_expression = NULL;
+ bytecode = NULL;
+ exclusion = NULL;
+ return ret;
}
/*
const struct lttng_domain *domain,
char *channel_name, struct lttng_event *event,
char *filter_expression,
- struct lttng_filter_bytecode *filter,
+ struct lttng_bytecode *filter,
struct lttng_event_exclusion *exclusion,
int wpipe)
{
/*
* Command LTTNG_LIST_TRACEPOINTS processed by the client thread.
*/
-ssize_t cmd_list_tracepoints(enum lttng_domain_type domain,
- struct lttng_event **events)
+enum lttng_error_code cmd_list_tracepoints(enum lttng_domain_type domain,
+ struct lttng_payload *reply_payload)
{
+ enum lttng_error_code ret_code;
int ret;
- ssize_t nb_events = 0;
+ ssize_t i, nb_events = 0;
+ struct lttng_event *events = NULL;
+ struct lttcomm_list_command_header reply_command_header = {};
+ size_t reply_command_header_offset;
+
+ assert(reply_payload);
+
+ /* Reserve space for command reply header. */
+ reply_command_header_offset = reply_payload->buffer.size;
+ ret = lttng_dynamic_buffer_set_size(&reply_payload->buffer,
+ reply_command_header_offset +
+ sizeof(struct lttcomm_list_command_header));
+ if (ret) {
+ ret_code = LTTNG_ERR_NOMEM;
+ goto error;
+ }
switch (domain) {
case LTTNG_DOMAIN_KERNEL:
- nb_events = kernel_list_events(events);
+ nb_events = kernel_list_events(&events);
if (nb_events < 0) {
- ret = LTTNG_ERR_KERN_LIST_FAIL;
+ ret_code = LTTNG_ERR_KERN_LIST_FAIL;
goto error;
}
break;
case LTTNG_DOMAIN_UST:
- nb_events = ust_app_list_events(events);
+ nb_events = ust_app_list_events(&events);
if (nb_events < 0) {
- ret = LTTNG_ERR_UST_LIST_FAIL;
+ ret_code = LTTNG_ERR_UST_LIST_FAIL;
goto error;
}
break;
case LTTNG_DOMAIN_LOG4J:
case LTTNG_DOMAIN_JUL:
case LTTNG_DOMAIN_PYTHON:
- nb_events = agent_list_events(events, domain);
+ nb_events = agent_list_events(&events, domain);
if (nb_events < 0) {
- ret = LTTNG_ERR_UST_LIST_FAIL;
+ ret_code = LTTNG_ERR_UST_LIST_FAIL;
goto error;
}
break;
default:
- ret = LTTNG_ERR_UND;
+ ret_code = LTTNG_ERR_UND;
+ goto error;
+ }
+
+ for (i = 0; i < nb_events; i++) {
+ ret = lttng_event_serialize(&events[i], 0, NULL, NULL, 0, NULL,
+ reply_payload);
+ if (ret) {
+ ret_code = LTTNG_ERR_NOMEM;
+ goto error;
+ }
+ }
+
+ if (nb_events > UINT32_MAX) {
+ ERR("Tracepoint count would overflow the tracepoint listing command's reply");
+ ret_code = LTTNG_ERR_OVERFLOW;
goto error;
}
- return nb_events;
+ /* Update command reply header. */
+ reply_command_header.count = (uint32_t) nb_events;
+ memcpy(reply_payload->buffer.data + reply_command_header_offset, &reply_command_header,
+ sizeof(reply_command_header));
+ ret_code = LTTNG_OK;
error:
- /* Return negative value to differentiate return code */
- return -ret;
+ free(events);
+ return ret_code;
}
/*
return -ret;
}
-ssize_t cmd_list_syscalls(struct lttng_event **events)
+enum lttng_error_code cmd_list_syscalls(
+ struct lttng_payload *reply_payload)
{
- return syscall_table_list(events);
+ enum lttng_error_code ret_code;
+ ssize_t nb_events, i;
+ int ret;
+ struct lttng_event *events = NULL;
+ struct lttcomm_list_command_header reply_command_header = {};
+ size_t reply_command_header_offset;
+
+ assert(reply_payload);
+
+ /* Reserve space for command reply header. */
+ reply_command_header_offset = reply_payload->buffer.size;
+ ret = lttng_dynamic_buffer_set_size(&reply_payload->buffer,
+ reply_command_header_offset +
+ sizeof(struct lttcomm_list_command_header));
+ if (ret) {
+ ret_code = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ nb_events = syscall_table_list(&events);
+ if (nb_events < 0) {
+ ret_code = (enum lttng_error_code) -nb_events;
+ goto end;
+ }
+
+ for (i = 0; i < nb_events; i++) {
+ ret = lttng_event_serialize(&events[i], 0, NULL, NULL, 0, NULL,
+ reply_payload);
+ if (ret) {
+ ret_code = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+ }
+
+ if (nb_events > UINT32_MAX) {
+ ERR("Syscall count would overflow the syscall listing command's reply");
+ ret_code = LTTNG_ERR_OVERFLOW;
+ goto end;
+ }
+
+ /* Update command reply header. */
+ reply_command_header.count = (uint32_t) nb_events;
+ memcpy(reply_payload->buffer.data + reply_command_header_offset, &reply_command_header,
+ sizeof(reply_command_header));
+
+ ret_code = LTTNG_OK;
+end:
+ free(events);
+ return ret_code;
}
/*
&payload,
0,
cmd_ctx->lsm.u.create_session.home_dir_size);
+ if (cmd_ctx->lsm.u.create_session.home_dir_size > 0 &&
+ !lttng_buffer_view_is_valid(&home_dir_view)) {
+ ERR("Invalid payload in \"create session\" command: buffer too short to contain home directory");
+ ret_code = LTTNG_ERR_INVALID_PROTOCOL;
+ goto error;
+ }
+
session_descriptor_view = lttng_buffer_view_from_dynamic_buffer(
&payload,
cmd_ctx->lsm.u.create_session.home_dir_size,
cmd_ctx->lsm.u.create_session.session_descriptor_size);
+ if (!lttng_buffer_view_is_valid(&session_descriptor_view)) {
+ ERR("Invalid payload in \"create session\" command: buffer too short to contain session descriptor");
+ ret_code = LTTNG_ERR_INVALID_PROTOCOL;
+ goto error;
+ }
ret = lttng_session_descriptor_create_from_buffer(
&session_descriptor_view, &session_descriptor);
payload_size_before_location = payload.size;
comm_ret = lttng_trace_archive_location_serialize(location,
&payload);
+ lttng_trace_archive_location_put(location);
if (comm_ret < 0) {
ERR("Failed to serialize the location of the trace archive produced during the destruction of session \"%s\"",
session->name);
/*
* Command LTTNG_LIST_CHANNELS processed by the client thread.
*/
-ssize_t cmd_list_channels(enum lttng_domain_type domain,
- struct ltt_session *session, struct lttng_channel **channels)
+enum lttng_error_code cmd_list_channels(enum lttng_domain_type domain,
+ struct ltt_session *session,
+ struct lttng_payload *payload)
{
- ssize_t nb_chan = 0, payload_size = 0, ret;
+ int ret = 0;
+ unsigned int i = 0;
+ struct lttcomm_list_command_header cmd_header = {};
+ size_t cmd_header_offset;
+ enum lttng_error_code ret_code;
+
+ assert(session);
+ assert(payload);
+
+ DBG("Listing channels for session %s", session->name);
+
+ cmd_header_offset = payload->buffer.size;
+
+ /* Reserve space for command reply header. */
+ ret = lttng_dynamic_buffer_set_size(&payload->buffer,
+ cmd_header_offset + sizeof(cmd_header));
+ if (ret) {
+ ret_code = LTTNG_ERR_NOMEM;
+ goto end;
+ }
switch (domain) {
case LTTNG_DOMAIN_KERNEL:
+ {
+ /* Kernel channels */
+ struct ltt_kernel_channel *kchan;
if (session->kernel_session != NULL) {
- nb_chan = session->kernel_session->channel_count;
- }
- DBG3("Number of kernel channels %zd", nb_chan);
- if (nb_chan <= 0) {
- ret = -LTTNG_ERR_KERN_CHAN_NOT_FOUND;
- goto end;
+ cds_list_for_each_entry(kchan,
+ &session->kernel_session->channel_list.head, list) {
+ uint64_t discarded_events, lost_packets;
+ struct lttng_channel_extended *extended;
+
+ extended = (struct lttng_channel_extended *)
+ kchan->channel->attr.extended.ptr;
+
+ ret = get_kernel_runtime_stats(session, kchan,
+ &discarded_events, &lost_packets);
+ if (ret < 0) {
+ ret_code = LTTNG_ERR_UNK;
+ goto end;
+ }
+
+ /*
+ * Update the discarded_events and lost_packets
+ * count for the channel
+ */
+ extended->discarded_events = discarded_events;
+ extended->lost_packets = lost_packets;
+
+ ret = lttng_channel_serialize(
+ kchan->channel, &payload->buffer);
+ if (ret) {
+ ERR("Failed to serialize lttng_channel: channel name = '%s'",
+ kchan->channel->name);
+ ret_code = LTTNG_ERR_UNK;
+ goto end;
+ }
+
+ i++;
+ }
}
break;
+ }
case LTTNG_DOMAIN_UST:
- if (session->ust_session != NULL) {
- rcu_read_lock();
- nb_chan = lttng_ht_get_count(
- session->ust_session->domain_global.channels);
- rcu_read_unlock();
- }
- DBG3("Number of UST global channels %zd", nb_chan);
- if (nb_chan < 0) {
- ret = -LTTNG_ERR_UST_CHAN_NOT_FOUND;
- goto end;
+ {
+ struct lttng_ht_iter iter;
+ struct ltt_ust_channel *uchan;
+
+ rcu_read_lock();
+ cds_lfht_for_each_entry(session->ust_session->domain_global.channels->ht,
+ &iter.iter, uchan, node.node) {
+ uint64_t discarded_events = 0, lost_packets = 0;
+ struct lttng_channel *channel = NULL;
+ struct lttng_channel_extended *extended;
+
+ channel = trace_ust_channel_to_lttng_channel(uchan);
+ if (!channel) {
+ ret = LTTNG_ERR_NOMEM;
+ break;
+ }
+
+ extended = (struct lttng_channel_extended *)
+ channel->attr.extended.ptr;
+
+ ret = get_ust_runtime_stats(session, uchan,
+ &discarded_events, &lost_packets);
+ if (ret < 0) {
+ lttng_channel_destroy(channel);
+ ret_code = LTTNG_ERR_UNK;
+ break;
+ }
+
+ extended->discarded_events = discarded_events;
+ extended->lost_packets = lost_packets;
+
+ ret = lttng_channel_serialize(
+ channel, &payload->buffer);
+ if (ret) {
+ ERR("Failed to serialize lttng_channel: channel name = '%s'",
+ channel->name);
+ ret_code = LTTNG_ERR_UNK;
+ ret = -1;
+ break;
+ }
+
+ i++;
}
+ rcu_read_unlock();
break;
+ }
default:
- ret = -LTTNG_ERR_UND;
- goto end;
+ break;
}
- if (nb_chan > 0) {
- const size_t channel_size = sizeof(struct lttng_channel) +
- sizeof(struct lttng_channel_extended);
- struct lttng_channel_extended *channel_exts;
-
- payload_size = nb_chan * channel_size;
- *channels = zmalloc(payload_size);
- if (*channels == NULL) {
- ret = -LTTNG_ERR_FATAL;
- goto end;
- }
-
- channel_exts = ((void *) *channels) +
- (nb_chan * sizeof(struct lttng_channel));
- ret = list_lttng_channels(domain, session, *channels, channel_exts);
- if (ret != LTTNG_OK) {
- free(*channels);
- *channels = NULL;
- goto end;
- }
- } else {
- *channels = NULL;
+ if (i > UINT32_MAX) {
+ ERR("Channel count would overflow the channel listing command's reply");
+ ret_code = LTTNG_ERR_OVERFLOW;
+ goto end;
}
- ret = payload_size;
+ /* Update command reply header. */
+ cmd_header.count = (uint32_t) i;
+ memcpy(payload->buffer.data + cmd_header_offset, &cmd_header,
+ sizeof(cmd_header));
+ ret_code = LTTNG_OK;
+
end:
- return ret;
+ return ret_code;
}
/*
* Command LTTNG_LIST_EVENTS processed by the client thread.
*/
-ssize_t cmd_list_events(enum lttng_domain_type domain,
- struct ltt_session *session, char *channel_name,
- struct lttng_payload *payload)
+enum lttng_error_code cmd_list_events(enum lttng_domain_type domain,
+ struct ltt_session *session,
+ char *channel_name,
+ struct lttng_payload *reply_payload)
{
- int ret = 0;
- ssize_t nb_events = 0;
- struct lttcomm_event_command_header cmd_header = {};
- const size_t cmd_header_offset = payload->buffer.size;
+ int buffer_resize_ret;
+ enum lttng_error_code ret_code = LTTNG_OK;
+ struct lttcomm_list_command_header reply_command_header = {};
+ size_t reply_command_header_offset;
+ unsigned int nb_events = 0;
- ret = lttng_dynamic_buffer_append(
- &payload->buffer, &cmd_header, sizeof(cmd_header));
- if (ret) {
- ret = LTTNG_ERR_NOMEM;
- goto error;
+ assert(reply_payload);
+
+ /* Reserve space for command reply header. */
+ reply_command_header_offset = reply_payload->buffer.size;
+ buffer_resize_ret = lttng_dynamic_buffer_set_size(&reply_payload->buffer,
+ reply_command_header_offset +
+ sizeof(struct lttcomm_list_command_header));
+ if (buffer_resize_ret) {
+ ret_code = LTTNG_ERR_NOMEM;
+ goto end;
}
switch (domain) {
case LTTNG_DOMAIN_KERNEL:
if (session->kernel_session != NULL) {
- nb_events = list_lttng_kernel_events(channel_name,
- session->kernel_session, payload);
+ ret_code = list_lttng_kernel_events(channel_name,
+ session->kernel_session, reply_payload, &nb_events);
}
+
break;
case LTTNG_DOMAIN_UST:
{
if (session->ust_session != NULL) {
- nb_events = list_lttng_ust_global_events(channel_name,
+ ret_code = list_lttng_ust_global_events(channel_name,
&session->ust_session->domain_global,
- payload);
+ reply_payload, &nb_events);
}
+
break;
}
case LTTNG_DOMAIN_LOG4J:
cds_lfht_for_each_entry(session->ust_session->agents->ht,
&iter.iter, agt, node.node) {
if (agt->domain == domain) {
- nb_events = list_lttng_agent_events(
- agt, payload);
+ ret_code = list_lttng_agent_events(
+ agt, reply_payload, &nb_events);
break;
}
}
+
rcu_read_unlock();
}
break;
default:
- ret = LTTNG_ERR_UND;
- goto error;
+ ret_code = LTTNG_ERR_UND;
+ break;
}
- ((struct lttcomm_event_command_header *) (payload->buffer.data +
- cmd_header_offset))->nb_events = (uint32_t) nb_events;
+ if (nb_events > UINT32_MAX) {
+ ret_code = LTTNG_ERR_OVERFLOW;
+ goto end;
+ }
- return nb_events;
+ /* Update command reply header. */
+ reply_command_header.count = (uint32_t) nb_events;
+ memcpy(reply_payload->buffer.data + reply_command_header_offset, &reply_command_header,
+ sizeof(reply_command_header));
-error:
- /* Return negative value to differentiate return code */
- return -ret;
+end:
+ return ret_code;
}
/*
/*
* Only list the sessions the user can control.
*/
- if (!session_access_ok(session, uid, gid) ||
+ if (!session_access_ok(session, uid) ||
session->destroyed) {
session_put(session);
continue;
* then regenerate the metadata. Live and per-pid sessions are not
* supported and return an error.
*
- * Return 0 on success or else a LTTNG_ERR code.
+ * Return LTTNG_OK on success or else a LTTNG_ERR code.
*/
int cmd_regenerate_metadata(struct ltt_session *session)
{
*
* Ask the tracer to regenerate a new statedump.
*
- * Return 0 on success or else a LTTNG_ERR code.
+ * Return LTTNG_OK on success or else a LTTNG_ERR code.
*/
int cmd_regenerate_statedump(struct ltt_session *session)
{
return ret;
}
-int cmd_register_trigger(struct command_ctx *cmd_ctx, int sock,
- struct notification_thread_handle *notification_thread)
+static
+enum lttng_error_code synchronize_tracer_notifier_register(
+ struct notification_thread_handle *notification_thread,
+ struct lttng_trigger *trigger, const struct lttng_credentials *cmd_creds)
{
- int ret;
- size_t trigger_len;
- ssize_t sock_recv_len;
- struct lttng_trigger *trigger = NULL;
- struct lttng_payload trigger_payload;
- struct lttng_credentials cmd_creds = {
- .uid = cmd_ctx->creds.uid,
- .gid = cmd_ctx->creds.gid,
- };
+ enum lttng_error_code ret_code;
+ const struct lttng_condition *condition =
+ lttng_trigger_get_const_condition(trigger);
+ const char *trigger_name;
+ uid_t trigger_owner;
+ enum lttng_trigger_status trigger_status;
+ const enum lttng_domain_type trigger_domain =
+ lttng_trigger_get_underlying_domain_type_restriction(
+ trigger);
+
+ trigger_status = lttng_trigger_get_owner_uid(trigger, &trigger_owner);
+ assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
+
+ assert(condition);
+ assert(lttng_condition_get_type(condition) ==
+ LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES);
+
+ trigger_status = lttng_trigger_get_name(trigger, &trigger_name);
+ trigger_name = trigger_status == LTTNG_TRIGGER_STATUS_OK ?
+ trigger_name : "(anonymous)";
- lttng_payload_init(&trigger_payload);
- trigger_len = (size_t) cmd_ctx->lsm.u.trigger.length;
- ret = lttng_dynamic_buffer_set_size(
- &trigger_payload.buffer, trigger_len);
- if (ret) {
- ret = LTTNG_ERR_NOMEM;
+ session_lock_list();
+ switch (trigger_domain) {
+ case LTTNG_DOMAIN_KERNEL:
+ {
+ ret_code = kernel_register_event_notifier(trigger, cmd_creds);
+ if (ret_code != LTTNG_OK) {
+ enum lttng_error_code notif_thread_unregister_ret;
+
+ notif_thread_unregister_ret =
+ notification_thread_command_unregister_trigger(
+ notification_thread, trigger);
+
+ if (notif_thread_unregister_ret != LTTNG_OK) {
+ /* Return the original error code. */
+ ERR("Failed to unregister trigger from notification thread during error recovery: trigger name = '%s', trigger owner uid = %d, error code = %d",
+ trigger_name,
+ (int) trigger_owner,
+ ret_code);
+ }
+ }
+ break;
+ }
+ case LTTNG_DOMAIN_UST:
+ ust_app_global_update_all_event_notifier_rules();
+ break;
+ case LTTNG_DOMAIN_JUL:
+ case LTTNG_DOMAIN_LOG4J:
+ case LTTNG_DOMAIN_PYTHON:
+ {
+ /* Agent domains. */
+ struct agent *agt = agent_find_by_event_notifier_domain(
+ trigger_domain);
+
+ if (!agt) {
+ agt = agent_create(trigger_domain);
+ if (!agt) {
+ ret_code = LTTNG_ERR_NOMEM;
+ goto end_unlock_session_list;
+ }
+
+ agent_add(agt, the_trigger_agents_ht_by_domain);
+ }
+
+ ret_code = trigger_agent_enable(trigger, agt);
+ if (ret_code != LTTNG_OK) {
+ goto end_unlock_session_list;
+ }
+
+ break;
+ }
+ case LTTNG_DOMAIN_NONE:
+ default:
+ abort();
+ }
+
+ ret_code = LTTNG_OK;
+end_unlock_session_list:
+ session_unlock_list();
+ return ret_code;
+}
+
+enum lttng_error_code cmd_register_trigger(const struct lttng_credentials *cmd_creds,
+ struct lttng_trigger *trigger,
+ bool is_trigger_anonymous,
+ struct notification_thread_handle *notification_thread,
+ struct lttng_trigger **return_trigger)
+{
+ enum lttng_error_code ret_code;
+ const char *trigger_name;
+ uid_t trigger_owner;
+ enum lttng_trigger_status trigger_status;
+
+ trigger_status = lttng_trigger_get_name(trigger, &trigger_name);
+ trigger_name = trigger_status == LTTNG_TRIGGER_STATUS_OK ?
+ trigger_name : "(anonymous)";
+
+ trigger_status = lttng_trigger_get_owner_uid(
+ trigger, &trigger_owner);
+ assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
+
+ DBG("Running register trigger command: trigger name = '%s', trigger owner uid = %d, command creds uid = %d",
+ trigger_name, (int) trigger_owner,
+ (int) lttng_credentials_get_uid(cmd_creds));
+
+ /*
+ * Validate the trigger credentials against the command credentials.
+ * Only the root user can register a trigger with non-matching
+ * credentials.
+ */
+ if (!lttng_credentials_is_equal_uid(
+ lttng_trigger_get_credentials(trigger),
+ cmd_creds)) {
+ if (lttng_credentials_get_uid(cmd_creds) != 0) {
+ ERR("Trigger credentials do not match the command credentials: trigger name = '%s', trigger owner uid = %d, command creds uid = %d",
+ trigger_name, (int) trigger_owner,
+ (int) lttng_credentials_get_uid(cmd_creds));
+ ret_code = LTTNG_ERR_INVALID_TRIGGER;
+ goto end;
+ }
+ }
+
+ /*
+ * The bytecode generation also serves as a validation step for the
+ * bytecode expressions.
+ */
+ ret_code = lttng_trigger_generate_bytecode(trigger, cmd_creds);
+ if (ret_code != LTTNG_OK) {
+ ERR("Failed to generate bytecode of trigger: trigger name = '%s', trigger owner uid = %d, error code = %d",
+ trigger_name, (int) trigger_owner, ret_code);
goto end;
}
- sock_recv_len = lttcomm_recv_unix_sock(
- sock, trigger_payload.buffer.data, trigger_len);
- if (sock_recv_len < 0 || sock_recv_len != trigger_len) {
- ERR("Failed to receive \"register trigger\" command payload");
- /* TODO: should this be a new error enum ? */
- ret = LTTNG_ERR_INVALID_TRIGGER;
+ /*
+ * A reference to the trigger is acquired by the notification thread.
+ * It is safe to return the same trigger to the caller since it the
+ * other user holds a reference.
+ *
+ * The trigger is modified during the execution of the
+ * "register trigger" command. However, by the time the command returns,
+ * it is safe to use without any locking as its properties are
+ * immutable.
+ */
+ ret_code = notification_thread_command_register_trigger(
+ notification_thread, trigger, is_trigger_anonymous);
+ if (ret_code != LTTNG_OK) {
+ DBG("Failed to register trigger to notification thread: trigger name = '%s', trigger owner uid = %d, error code = %d",
+ trigger_name, (int) trigger_owner, ret_code);
goto end;
}
- /* Receive fds, if any. */
- if (cmd_ctx->lsm.fd_count > 0) {
- ret = lttcomm_recv_payload_fds_unix_sock(
- sock, cmd_ctx->lsm.fd_count, &trigger_payload);
- if (ret > 0 && ret != cmd_ctx->lsm.fd_count * sizeof(int)) {
- ret = LTTNG_ERR_INVALID_PROTOCOL;
- goto end;
- } else if (ret <= 0) {
- ret = LTTNG_ERR_FATAL;
+ trigger_status = lttng_trigger_get_name(trigger, &trigger_name);
+ trigger_name = trigger_status == LTTNG_TRIGGER_STATUS_OK ?
+ trigger_name : "(anonymous)";
+
+ /*
+ * Synchronize tracers if the trigger adds an event notifier.
+ */
+ if (lttng_trigger_needs_tracer_notifier(trigger)) {
+ ret_code = synchronize_tracer_notifier_register(notification_thread,
+ trigger, cmd_creds);
+ if (ret_code != LTTNG_OK) {
+ ERR("Error registering tracer notifier: %s",
+ lttng_strerror(-ret_code));
goto end;
}
}
- /* Deserialize trigger. */
+ /*
+ * Return an updated trigger to the client.
+ *
+ * Since a modified version of the same trigger is returned, acquire a
+ * reference to the trigger so the caller doesn't have to care if those
+ * are distinct instances or not.
+ */
+ if (ret_code == LTTNG_OK) {
+ lttng_trigger_get(trigger);
+ *return_trigger = trigger;
+ /* Ownership of trigger was transferred to caller. */
+ trigger = NULL;
+ }
+end:
+ return ret_code;
+}
+
+static
+enum lttng_error_code synchronize_tracer_notifier_unregister(
+ const struct lttng_trigger *trigger)
+{
+ enum lttng_error_code ret_code;
+ const struct lttng_condition *condition =
+ lttng_trigger_get_const_condition(trigger);
+ const enum lttng_domain_type trigger_domain =
+ lttng_trigger_get_underlying_domain_type_restriction(
+ trigger);
+
+ assert(condition);
+ assert(lttng_condition_get_type(condition) ==
+ LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES);
+
+ session_lock_list();
+ switch (trigger_domain) {
+ case LTTNG_DOMAIN_KERNEL:
+ ret_code = kernel_unregister_event_notifier(trigger);
+ if (ret_code != LTTNG_OK) {
+ goto end_unlock_session_list;
+ }
+
+ break;
+ case LTTNG_DOMAIN_UST:
+ ust_app_global_update_all_event_notifier_rules();
+ break;
+ case LTTNG_DOMAIN_JUL:
+ case LTTNG_DOMAIN_LOG4J:
+ case LTTNG_DOMAIN_PYTHON:
{
- struct lttng_payload_view view =
- lttng_payload_view_from_payload(
- &trigger_payload, 0, -1);
-
- if (lttng_trigger_create_from_payload(&view, &trigger) !=
- trigger_len) {
- ERR("Invalid trigger payload received in \"register trigger\" command");
- ret = LTTNG_ERR_INVALID_TRIGGER;
+ /* Agent domains. */
+ struct agent *agt = agent_find_by_event_notifier_domain(
+ trigger_domain);
+
+ /*
+ * This trigger was never registered in the first place. Calling
+ * this function under those circumstances is an internal error.
+ */
+ assert(agt);
+ ret_code = trigger_agent_disable(trigger, agt);
+ if (ret_code != LTTNG_OK) {
+ goto end_unlock_session_list;
+ }
+
+ break;
+ }
+ case LTTNG_DOMAIN_NONE:
+ default:
+ abort();
+ }
+
+ ret_code = LTTNG_OK;
+
+end_unlock_session_list:
+ session_unlock_list();
+ return ret_code;
+}
+
+enum lttng_error_code cmd_unregister_trigger(const struct lttng_credentials *cmd_creds,
+ const struct lttng_trigger *trigger,
+ struct notification_thread_handle *notification_thread)
+{
+ enum lttng_error_code ret_code;
+ const char *trigger_name;
+ uid_t trigger_owner;
+ enum lttng_trigger_status trigger_status;
+ struct lttng_trigger *sessiond_trigger = NULL;
+
+ trigger_status = lttng_trigger_get_name(trigger, &trigger_name);
+ trigger_name = trigger_status == LTTNG_TRIGGER_STATUS_OK ? trigger_name : "(anonymous)";
+ trigger_status = lttng_trigger_get_owner_uid(trigger, &trigger_owner);
+ assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
+
+ DBG("Running unregister trigger command: trigger name = '%s', trigger owner uid = %d, command creds uid = %d",
+ trigger_name, (int) trigger_owner,
+ (int) lttng_credentials_get_uid(cmd_creds));
+
+ /*
+ * Validate the trigger credentials against the command credentials.
+ * Only the root user can unregister a trigger with non-matching
+ * credentials.
+ */
+ if (!lttng_credentials_is_equal_uid(
+ lttng_trigger_get_credentials(trigger),
+ cmd_creds)) {
+ if (lttng_credentials_get_uid(cmd_creds) != 0) {
+ ERR("Trigger credentials do not match the command credentials: trigger name = '%s', trigger owner uid = %d, command creds uid = %d",
+ trigger_name, (int) trigger_owner,
+ (int) lttng_credentials_get_uid(cmd_creds));
+ ret_code = LTTNG_ERR_INVALID_TRIGGER;
goto end;
}
}
- /* Set the trigger credential */
- lttng_trigger_set_credentials(trigger, &cmd_creds);
+ /* Fetch the sessiond side trigger object. */
+ ret_code = notification_thread_command_get_trigger(
+ notification_thread, trigger, &sessiond_trigger);
+ if (ret_code != LTTNG_OK) {
+ DBG("Failed to get trigger from notification thread during unregister: trigger name = '%s', trigger owner uid = %d, error code = %d",
+ trigger_name, (int) trigger_owner, ret_code);
+ goto end;
+ }
+
+ assert(sessiond_trigger);
+
+ /*
+ * From this point on, no matter what, consider the trigger
+ * unregistered.
+ *
+ * We set the unregistered state of the sessiond side trigger object in
+ * the client thread since we want to minimize the possibility of the
+ * notification thread being stalled due to a long execution of an
+ * action that required the trigger lock.
+ */
+ lttng_trigger_set_as_unregistered(sessiond_trigger);
+
+ ret_code = notification_thread_command_unregister_trigger(notification_thread,
+ trigger);
+ if (ret_code != LTTNG_OK) {
+ DBG("Failed to unregister trigger from notification thread: trigger name = '%s', trigger owner uid = %d, error code = %d",
+ trigger_name, (int) trigger_owner, ret_code);
+ goto end;
+ }
+
+ /*
+ * Synchronize tracers if the trigger removes an event notifier.
+ * Do this even if the trigger unregistration failed to at least stop
+ * the tracers from producing notifications associated with this
+ * event notifier.
+ */
+ if (lttng_trigger_needs_tracer_notifier(trigger)) {
+ ret_code = synchronize_tracer_notifier_unregister(trigger);
+ if (ret_code != LTTNG_OK) {
+ ERR("Error unregistering trigger to tracer.");
+ goto end;
+ }
+
+ }
- /* Inform the notification thread */
- ret = notification_thread_command_register_trigger(notification_thread,
- trigger);
- /* Ownership of trigger was transferred. */
- trigger = NULL;
end:
- lttng_trigger_destroy(trigger);
- lttng_payload_reset(&trigger_payload);
- return ret;
+ lttng_trigger_put(sessiond_trigger);
+ return ret_code;
}
-int cmd_unregister_trigger(struct command_ctx *cmd_ctx, int sock,
- struct notification_thread_handle *notification_thread)
+enum lttng_error_code cmd_list_triggers(struct command_ctx *cmd_ctx,
+ struct notification_thread_handle *notification_thread,
+ struct lttng_triggers **return_triggers)
{
int ret;
- size_t trigger_len;
- ssize_t sock_recv_len;
- struct lttng_trigger *trigger = NULL;
- struct lttng_payload trigger_payload;
- struct lttng_credentials cmd_creds = {
- .uid = cmd_ctx->creds.uid,
- .gid = cmd_ctx->creds.gid,
- };
+ enum lttng_error_code ret_code;
+ struct lttng_triggers *triggers = NULL;
+
+ /* Get the set of triggers from the notification thread. */
+ ret_code = notification_thread_command_list_triggers(
+ notification_thread, cmd_ctx->creds.uid, &triggers);
+ if (ret_code != LTTNG_OK) {
+ goto end;
+ }
- lttng_payload_init(&trigger_payload);
- trigger_len = (size_t) cmd_ctx->lsm.u.trigger.length;
- ret = lttng_dynamic_buffer_set_size(
- &trigger_payload.buffer, trigger_len);
+ ret = lttng_triggers_remove_hidden_triggers(triggers);
if (ret) {
- ret = LTTNG_ERR_NOMEM;
+ ret_code = LTTNG_ERR_UNK;
+ goto end;
+ }
+
+ *return_triggers = triggers;
+ triggers = NULL;
+ ret_code = LTTNG_OK;
+end:
+ lttng_triggers_destroy(triggers);
+ return ret_code;
+}
+
+enum lttng_error_code cmd_execute_error_query(const struct lttng_credentials *cmd_creds,
+ const struct lttng_error_query *query,
+ struct lttng_error_query_results **_results,
+ struct notification_thread_handle *notification_thread)
+{
+ enum lttng_error_code ret_code;
+ const struct lttng_trigger *query_target_trigger;
+ const struct lttng_action *query_target_action = NULL;
+ struct lttng_trigger *matching_trigger = NULL;
+ const char *trigger_name;
+ uid_t trigger_owner;
+ enum lttng_trigger_status trigger_status;
+ struct lttng_error_query_results *results = NULL;
+
+ switch (lttng_error_query_get_target_type(query)) {
+ case LTTNG_ERROR_QUERY_TARGET_TYPE_TRIGGER:
+ query_target_trigger = lttng_error_query_trigger_borrow_target(query);
+ break;
+ case LTTNG_ERROR_QUERY_TARGET_TYPE_CONDITION:
+ query_target_trigger =
+ lttng_error_query_condition_borrow_target(query);
+ break;
+ case LTTNG_ERROR_QUERY_TARGET_TYPE_ACTION:
+ query_target_trigger = lttng_error_query_action_borrow_trigger_target(
+ query);
+ break;
+ default:
+ abort();
+ }
+
+ assert(query_target_trigger);
+
+ ret_code = notification_thread_command_get_trigger(notification_thread,
+ query_target_trigger, &matching_trigger);
+ if (ret_code != LTTNG_OK) {
goto end;
}
- sock_recv_len = lttcomm_recv_unix_sock(
- sock, trigger_payload.buffer.data, trigger_len);
- if (sock_recv_len < 0 || sock_recv_len != trigger_len) {
- ERR("Failed to receive \"unregister trigger\" command payload");
- /* TODO: should this be a new error enum ? */
- ret = LTTNG_ERR_INVALID_TRIGGER;
+ /* No longer needed. */
+ query_target_trigger = NULL;
+
+ if (lttng_error_query_get_target_type(query) ==
+ LTTNG_ERROR_QUERY_TARGET_TYPE_ACTION) {
+ /* Get the sessiond-side version of the target action. */
+ query_target_action =
+ lttng_error_query_action_borrow_action_target(
+ query, matching_trigger);
+ }
+
+ trigger_status = lttng_trigger_get_name(matching_trigger, &trigger_name);
+ trigger_name = trigger_status == LTTNG_TRIGGER_STATUS_OK ?
+ trigger_name : "(anonymous)";
+ trigger_status = lttng_trigger_get_owner_uid(matching_trigger,
+ &trigger_owner);
+ assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
+
+ results = lttng_error_query_results_create();
+ if (!results) {
+ ret_code = LTTNG_ERR_NOMEM;
goto end;
}
- /* Receive fds, if any. */
- if (cmd_ctx->lsm.fd_count > 0) {
- ret = lttcomm_recv_payload_fds_unix_sock(
- sock, cmd_ctx->lsm.fd_count, &trigger_payload);
- if (ret > 0 && ret != cmd_ctx->lsm.fd_count * sizeof(int)) {
- ret = LTTNG_ERR_INVALID_PROTOCOL;
- goto end;
- } else if (ret <= 0) {
- ret = LTTNG_ERR_FATAL;
+ DBG("Running \"execute error query\" command: trigger name = '%s', trigger owner uid = %d, command creds uid = %d",
+ trigger_name, (int) trigger_owner,
+ (int) lttng_credentials_get_uid(cmd_creds));
+
+ /*
+ * Validate the trigger credentials against the command credentials.
+ * Only the root user can target a trigger with non-matching
+ * credentials.
+ */
+ if (!lttng_credentials_is_equal_uid(
+ lttng_trigger_get_credentials(matching_trigger),
+ cmd_creds)) {
+ if (lttng_credentials_get_uid(cmd_creds) != 0) {
+ ERR("Trigger credentials do not match the command credentials: trigger name = '%s', trigger owner uid = %d, command creds uid = %d",
+ trigger_name, (int) trigger_owner,
+ (int) lttng_credentials_get_uid(cmd_creds));
+ ret_code = LTTNG_ERR_INVALID_TRIGGER;
goto end;
}
}
+ switch (lttng_error_query_get_target_type(query)) {
+ case LTTNG_ERROR_QUERY_TARGET_TYPE_TRIGGER:
+ trigger_status = lttng_trigger_add_error_results(
+ matching_trigger, results);
+
+ switch (trigger_status) {
+ case LTTNG_TRIGGER_STATUS_OK:
+ break;
+ default:
+ ret_code = LTTNG_ERR_UNK;
+ goto end;
+ }
+
+ break;
+ case LTTNG_ERROR_QUERY_TARGET_TYPE_CONDITION:
{
- struct lttng_payload_view view =
- lttng_payload_view_from_payload(
- &trigger_payload, 0, -1);
-
- if (lttng_trigger_create_from_payload(&view, &trigger) !=
- trigger_len) {
- ERR("Invalid trigger payload received in \"unregister trigger\" command");
- ret = LTTNG_ERR_INVALID_TRIGGER;
+ trigger_status = lttng_trigger_condition_add_error_results(
+ matching_trigger, results);
+
+ switch (trigger_status) {
+ case LTTNG_TRIGGER_STATUS_OK:
+ break;
+ default:
+ ret_code = LTTNG_ERR_UNK;
goto end;
}
+
+ break;
}
+ case LTTNG_ERROR_QUERY_TARGET_TYPE_ACTION:
+ {
+ const enum lttng_action_status action_status =
+ lttng_action_add_error_query_results(
+ query_target_action, results);
+
+ switch (action_status) {
+ case LTTNG_ACTION_STATUS_OK:
+ break;
+ default:
+ ret_code = LTTNG_ERR_UNK;
+ goto end;
+ }
- lttng_trigger_set_credentials(trigger, &cmd_creds);
+ break;
+ }
+ default:
+ abort();
+ break;
+ }
- ret = notification_thread_command_unregister_trigger(notification_thread,
- trigger);
+ *_results = results;
+ results = NULL;
+ ret_code = LTTNG_OK;
end:
- lttng_trigger_destroy(trigger);
- lttng_payload_reset(&trigger_payload);
- return ret;
+ lttng_trigger_put(matching_trigger);
+ lttng_error_query_results_destroy(results);
+ return ret_code;
}
/*
consumer_copy_output(snapshot_output->consumer);
strcpy(snapshot_kernel_consumer_output->chunk_path,
snapshot_chunk_name);
+
+ /* Copy the original domain subdir. */
+ strcpy(snapshot_kernel_consumer_output->domain_subdir,
+ original_kernel_consumer_output->domain_subdir);
+
ret = consumer_copy_sockets(snapshot_kernel_consumer_output,
original_kernel_consumer_output);
if (ret < 0) {
consumer_copy_output(snapshot_output->consumer);
strcpy(snapshot_ust_consumer_output->chunk_path,
snapshot_chunk_name);
+
+ /* Copy the original domain subdir. */
+ strcpy(snapshot_ust_consumer_output->domain_subdir,
+ original_ust_consumer_output->domain_subdir);
+
ret = consumer_copy_sockets(snapshot_ust_consumer_output,
original_ust_consumer_output);
if (ret < 0) {
session->name);
ret_code = LTTNG_ERR_CLOSE_TRACE_CHUNK_FAIL_CONSUMER;
}
+
+ lttng_trace_chunk_put(snapshot_trace_chunk);
+ snapshot_trace_chunk = NULL;
error:
if (original_ust_consumer_output) {
session->ust_session->consumer = original_ust_consumer_output;
sizeof(session->shm_path));
session->shm_path[sizeof(session->shm_path) - 1] = '\0';
- return 0;
+ return LTTNG_OK;
}
/*
chunk_being_archived = NULL;
if (!quiet_rotation) {
ret = notification_thread_command_session_rotation_ongoing(
- notification_thread_handle,
- session->name, session->uid, session->gid,
+ the_notification_thread_handle, session->name,
+ session->uid, session->gid,
ongoing_rotation_chunk_id);
if (ret != LTTNG_OK) {
ERR("Failed to notify notification thread that a session rotation is ongoing for session %s",
* 'activate' to false means deactivate the rotation schedule and validate that
* 'new_value' has the same value as the currently active value.
*
- * Return 0 on success or else a positive LTTNG_ERR code.
+ * Return LTTNG_OK on success or else a positive LTTNG_ERR code.
*/
int cmd_rotation_set_schedule(struct ltt_session *session,
bool activate, enum lttng_rotation_schedule_type schedule_type,