--- /dev/null
+/*
+ * Copyright (C) 2021 Simon Marchi <simon.marchi@efficios.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-only
+ *
+ */
+
+#include <stdio.h>
+
+#include "../command.h"
+
+#include "common/argpar/argpar.h"
+#include "common/dynamic-array.h"
+#include "common/mi-lttng.h"
+/* For lttng_condition_type_str(). */
+#include "lttng/condition/condition-internal.h"
+/* For lttng_domain_type_str(). */
+#include "lttng/domain-internal.h"
+
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-list-trigger.1.h>
+;
+#endif
+
+enum {
+ OPT_HELP,
+ OPT_LIST_OPTIONS,
+};
+
+static const
+struct argpar_opt_descr list_trigger_options[] = {
+ { OPT_HELP, 'h', "help", false },
+ { OPT_LIST_OPTIONS, '\0', "list-options", false },
+ ARGPAR_OPT_DESCR_SENTINEL,
+};
+
+static
+void print_event_rule_tracepoint(const struct lttng_event_rule *event_rule)
+{
+ enum lttng_event_rule_status event_rule_status;
+ enum lttng_domain_type domain_type;
+ const char *pattern;
+ const char *filter;
+ int log_level;
+ unsigned int exclusions_count;
+ int i;
+
+ event_rule_status = lttng_event_rule_tracepoint_get_pattern(
+ event_rule, &pattern);
+ assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK);
+
+ event_rule_status = lttng_event_rule_tracepoint_get_domain_type(
+ event_rule, &domain_type);
+ assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK);
+
+ _MSG(" rule: %s (type: tracepoint, domain: %s", pattern,
+ lttng_domain_type_str(domain_type));
+
+ event_rule_status = lttng_event_rule_tracepoint_get_filter(
+ event_rule, &filter);
+ if (event_rule_status == LTTNG_EVENT_RULE_STATUS_OK) {
+ _MSG(", filter: %s", filter);
+ } else {
+ assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_UNSET);
+ }
+
+ event_rule_status = lttng_event_rule_tracepoint_get_log_level(
+ event_rule, &log_level);
+ if (event_rule_status == LTTNG_EVENT_RULE_STATUS_OK) {
+ enum lttng_loglevel_type log_level_type;
+ const char *log_level_op;
+
+ event_rule_status = lttng_event_rule_tracepoint_get_log_level_type(
+ event_rule, &log_level_type);
+ assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK);
+ assert(log_level_type == LTTNG_EVENT_LOGLEVEL_RANGE ||
+ log_level_type == LTTNG_EVENT_LOGLEVEL_SINGLE);
+
+ log_level_op = (log_level_type == LTTNG_EVENT_LOGLEVEL_RANGE ? "<=" : "==");
+
+ _MSG(", log level %s %s", log_level_op,
+ mi_lttng_loglevel_string(
+ log_level, domain_type));
+ } else {
+ assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_UNSET);
+ }
+
+ event_rule_status = lttng_event_rule_tracepoint_get_exclusions_count(
+ event_rule, &exclusions_count);
+ assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK);
+ if (exclusions_count > 0) {
+ _MSG(", exclusions: ");
+ for (i = 0; i < exclusions_count; i++) {
+ const char *exclusion;
+
+ event_rule_status = lttng_event_rule_tracepoint_get_exclusion_at_index(
+ event_rule, i, &exclusion);
+ assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK);
+
+ _MSG("%s%s", i > 0 ? "," : "", exclusion);
+ }
+ }
+
+ MSG(")");
+}
+
+static void print_kernel_probe_location(
+ const struct lttng_kernel_probe_location *location)
+{
+ enum lttng_kernel_probe_location_status status;
+ switch (lttng_kernel_probe_location_get_type(location)) {
+ case LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS:
+ {
+ uint64_t address;
+
+ status = lttng_kernel_probe_location_address_get_address(
+ location, &address);
+ if (status != LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK) {
+ ERR("Getting kernel probe location address failed.");
+ goto end;
+ }
+
+ _MSG("0x%" PRIx64, address);
+
+ break;
+ }
+ case LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET:
+ {
+ uint64_t offset;
+ const char *symbol_name;
+
+ symbol_name = lttng_kernel_probe_location_symbol_get_name(
+ location);
+ if (!symbol_name) {
+ ERR("Getting kernel probe location symbol name failed.");
+ goto end;
+ }
+
+ status = lttng_kernel_probe_location_symbol_get_offset(
+ location, &offset);
+ if (status != LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK) {
+ ERR("Getting kernel probe location address failed.");
+ goto end;
+ }
+
+ if (offset == 0) {
+ _MSG("%s", symbol_name);
+ } else {
+ _MSG("%s+0x%" PRIx64, symbol_name, offset);
+ }
+
+ break;
+ }
+ default:
+ abort();
+ };
+end:
+ return;
+}
+
+static
+void print_event_rule_kprobe(const struct lttng_event_rule *event_rule)
+{
+ enum lttng_event_rule_status event_rule_status;
+ const char *name;
+ const struct lttng_kernel_probe_location *location;
+
+ assert(lttng_event_rule_get_type(event_rule) == LTTNG_EVENT_RULE_TYPE_KPROBE);
+
+ event_rule_status = lttng_event_rule_kprobe_get_name(event_rule, &name);
+ if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) {
+ ERR("Failed to get kprobe event rule's name.");
+ goto end;
+ }
+
+ event_rule_status = lttng_event_rule_kprobe_get_location(
+ event_rule, &location);
+ if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) {
+ ERR("Failed to get kprobe event rule's location.");
+ goto end;
+ }
+
+ _MSG(" rule: %s (type: probe, location: ", name);
+
+ print_kernel_probe_location(location);
+
+ MSG(")");
+
+end:
+ return;
+}
+
+static
+void print_event_rule_uprobe(const struct lttng_event_rule *event_rule)
+{
+ enum lttng_event_rule_status event_rule_status;
+ const char *name;
+ const struct lttng_userspace_probe_location *location;
+ enum lttng_userspace_probe_location_type userspace_probe_location_type;
+
+ assert(lttng_event_rule_get_type(event_rule) == LTTNG_EVENT_RULE_TYPE_UPROBE);
+
+ event_rule_status = lttng_event_rule_uprobe_get_name(event_rule, &name);
+ if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) {
+ ERR("Failed to get uprobe event rule's name.");
+ goto end;
+ }
+
+ event_rule_status = lttng_event_rule_uprobe_get_location(
+ event_rule, &location);
+ if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) {
+ ERR("Failed to get uprobe event rule's location.");
+ goto end;
+ }
+
+ _MSG(" rule: %s (type: userspace probe, location: ", name);
+
+ userspace_probe_location_type =
+ lttng_userspace_probe_location_get_type(location);
+
+ switch (userspace_probe_location_type) {
+ case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION:
+ {
+ const char *binary_path, *function_name;
+
+ binary_path = lttng_userspace_probe_location_function_get_binary_path(
+ location);
+ function_name = lttng_userspace_probe_location_function_get_function_name(
+ location);
+
+ _MSG("%s:%s", binary_path, function_name);
+ break;
+ }
+ case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT:
+ _MSG("SDT not implemented yet");
+ break;
+ default:
+ abort();
+ }
+
+ MSG(")");
+
+end:
+ return;
+}
+
+static
+void print_event_rule_syscall(const struct lttng_event_rule *event_rule)
+{
+ const char *pattern, *filter;
+ enum lttng_event_rule_status event_rule_status;
+
+ assert(lttng_event_rule_get_type(event_rule) == LTTNG_EVENT_RULE_TYPE_SYSCALL);
+
+ event_rule_status = lttng_event_rule_syscall_get_pattern(
+ event_rule, &pattern);
+ assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK);
+
+ _MSG(" rule: %s (type: syscall", pattern);
+
+ event_rule_status = lttng_event_rule_syscall_get_filter(
+ event_rule, &filter);
+ if (event_rule_status == LTTNG_EVENT_RULE_STATUS_OK) {
+ _MSG(", filter: %s", filter);
+ } else {
+ assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_UNSET);
+ }
+
+ MSG(")");
+}
+
+static
+void print_event_rule(const struct lttng_event_rule *event_rule)
+{
+ const enum lttng_event_rule_type event_rule_type =
+ lttng_event_rule_get_type(event_rule);
+
+ switch (event_rule_type) {
+ case LTTNG_EVENT_RULE_TYPE_TRACEPOINT:
+ print_event_rule_tracepoint(event_rule);
+ break;
+ case LTTNG_EVENT_RULE_TYPE_KPROBE:
+ print_event_rule_kprobe(event_rule);
+ break;
+ case LTTNG_EVENT_RULE_TYPE_UPROBE:
+ print_event_rule_uprobe(event_rule);
+ break;
+ case LTTNG_EVENT_RULE_TYPE_SYSCALL:
+ print_event_rule_syscall(event_rule);
+ break;
+ default:
+ abort();
+ }
+}
+
+static
+void print_condition_event_rule_hit(const struct lttng_condition *condition)
+{
+ const struct lttng_event_rule *event_rule;
+ enum lttng_condition_status condition_status;
+
+ condition_status =
+ lttng_condition_event_rule_get_rule(condition, &event_rule);
+ assert(condition_status == LTTNG_CONDITION_STATUS_OK);
+
+ print_event_rule(event_rule);
+}
+
+static
+void print_one_action(const struct lttng_action *action)
+{
+ enum lttng_action_type action_type;
+ enum lttng_action_status action_status;
+ const char *value;
+
+ action_type = lttng_action_get_type(action);
+ assert(action_type != LTTNG_ACTION_TYPE_GROUP);
+
+ switch (action_type) {
+ case LTTNG_ACTION_TYPE_NOTIFY:
+ MSG("notify");
+ break;
+ case LTTNG_ACTION_TYPE_START_SESSION:
+ action_status = lttng_action_start_session_get_session_name(
+ action, &value);
+ assert(action_status == LTTNG_ACTION_STATUS_OK);
+ MSG("start session `%s`", value);
+ break;
+ case LTTNG_ACTION_TYPE_STOP_SESSION:
+ action_status = lttng_action_stop_session_get_session_name(
+ action, &value);
+ assert(action_status == LTTNG_ACTION_STATUS_OK);
+ MSG("stop session `%s`", value);
+ break;
+ case LTTNG_ACTION_TYPE_ROTATE_SESSION:
+ action_status = lttng_action_rotate_session_get_session_name(
+ action, &value);
+ assert(action_status == LTTNG_ACTION_STATUS_OK);
+ MSG("rotate session `%s`", value);
+ break;
+ case LTTNG_ACTION_TYPE_SNAPSHOT_SESSION:
+ {
+ const struct lttng_snapshot_output *output;
+
+ action_status = lttng_action_snapshot_session_get_session_name(
+ action, &value);
+ assert(action_status == LTTNG_ACTION_STATUS_OK);
+ _MSG("snapshot session `%s`", value);
+
+ action_status = lttng_action_snapshot_session_get_output(
+ action, &output);
+ if (action_status == LTTNG_ACTION_STATUS_OK) {
+ const char *name;
+ uint64_t max_size;
+ const char *ctrl_url, *data_url;
+ bool starts_with_file, starts_with_net, starts_with_net6;
+
+ ctrl_url = lttng_snapshot_output_get_ctrl_url(output);
+ assert(ctrl_url && strlen(ctrl_url) > 0);
+
+ data_url = lttng_snapshot_output_get_data_url(output);
+ assert(data_url);
+
+ starts_with_file = strncmp(ctrl_url, "file://", strlen("file://")) == 0;
+ starts_with_net = strncmp(ctrl_url, "net://", strlen("net://")) == 0;
+ starts_with_net6 = strncmp(ctrl_url, "net6://", strlen("net6://")) == 0;
+
+ if (ctrl_url[0] == '/' || starts_with_file) {
+ if (starts_with_file) {
+ ctrl_url += strlen("file://");
+ }
+
+ _MSG(", path: %s", ctrl_url);
+ } else if (starts_with_net || starts_with_net6) {
+ _MSG(", url: %s", ctrl_url);
+ } else {
+ assert(strlen(data_url) > 0);
+
+ _MSG(", control url: %s, data url: %s", ctrl_url, data_url);
+ }
+
+ name = lttng_snapshot_output_get_name(output);
+ assert(name);
+ if (strlen(name) > 0) {
+ _MSG(", name: %s", name);
+ }
+
+ max_size = lttng_snapshot_output_get_maxsize(output);
+ if (max_size != -1ULL) {
+ _MSG(", max size: %" PRIu64, max_size);
+ }
+ }
+
+ MSG("");
+ break;
+ }
+
+ default:
+ abort();
+ }
+}
+
+static
+void print_one_trigger(const struct lttng_trigger *trigger)
+{
+ const struct lttng_condition *condition;
+ enum lttng_condition_type condition_type;
+ const struct lttng_action *action;
+ enum lttng_action_type action_type;
+ enum lttng_trigger_status trigger_status;
+ const char *name;
+ enum lttng_trigger_firing_policy firing_policy_type;
+ uint64_t threshold;
+ uid_t trigger_uid;
+
+ trigger_status = lttng_trigger_get_name(trigger, &name);
+ assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
+
+ trigger_status = lttng_trigger_get_owner_uid(trigger, &trigger_uid);
+ assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
+
+ MSG("- id: %s", name);
+ MSG(" user id: %d", trigger_uid);
+
+ trigger_status = lttng_trigger_get_firing_policy(
+ trigger, &firing_policy_type, &threshold);
+ if (trigger_status != LTTNG_TRIGGER_STATUS_OK) {
+ ERR("Failed to get trigger's policy.");
+ goto end;
+ }
+
+ switch (firing_policy_type) {
+ case LTTNG_TRIGGER_FIRING_POLICY_EVERY_N:
+ if (threshold > 1) {
+ MSG(" firing policy: after every %" PRIu64 " occurences", threshold);
+ }
+ break;
+ case LTTNG_TRIGGER_FIRING_POLICY_ONCE_AFTER_N:
+ MSG(" firing policy: once after %" PRIu64 " occurences", threshold);
+ break;
+ default:
+ abort();
+ }
+
+ condition = lttng_trigger_get_const_condition(trigger);
+ condition_type = lttng_condition_get_type(condition);
+ MSG(" condition: %s", lttng_condition_type_str(condition_type));
+ switch (condition_type) {
+ case LTTNG_CONDITION_TYPE_EVENT_RULE_HIT:
+ print_condition_event_rule_hit(condition);
+ break;
+ default:
+ MSG(" (condition type not handled in %s)", __func__);
+ break;
+ }
+
+ action = lttng_trigger_get_const_action(trigger);
+ action_type = lttng_action_get_type(action);
+ if (action_type == LTTNG_ACTION_TYPE_GROUP) {
+ unsigned int count, i;
+ enum lttng_action_status action_status;
+
+ MSG(" actions:");
+
+ action_status = lttng_action_group_get_count(action, &count);
+ assert(action_status == LTTNG_ACTION_STATUS_OK);
+
+ for (i = 0; i < count; i++) {
+ const struct lttng_action *subaction =
+ lttng_action_group_get_at_index(
+ action, i);
+
+ _MSG(" ");
+ print_one_action(subaction);
+ }
+ } else {
+ _MSG(" action:");
+ print_one_action(action);
+ }
+
+end:
+ return;
+}
+
+static
+int compare_triggers_by_name(const void *a, const void *b)
+{
+ const struct lttng_trigger *trigger_a = *((const struct lttng_trigger **) a);
+ const struct lttng_trigger *trigger_b = *((const struct lttng_trigger **) b);
+ const char *name_a, *name_b;
+ enum lttng_trigger_status trigger_status;
+
+ trigger_status = lttng_trigger_get_name(trigger_a, &name_a);
+ assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
+
+ trigger_status = lttng_trigger_get_name(trigger_b, &name_b);
+ assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
+
+ return strcmp(name_a, name_b);
+}
+
+int cmd_list_triggers(int argc, const char **argv)
+{
+ int ret;
+ struct argpar_parse_ret argpar_parse_ret = {};
+ struct lttng_triggers *triggers = NULL;
+ int i;
+ struct lttng_dynamic_pointer_array sorted_triggers;
+ enum lttng_trigger_status trigger_status;
+ unsigned int num_triggers;
+
+ lttng_dynamic_pointer_array_init(&sorted_triggers, NULL);
+
+ argpar_parse_ret = argpar_parse(
+ argc - 1, argv + 1, list_trigger_options, true);
+ if (!argpar_parse_ret.items) {
+ ERR("%s", argpar_parse_ret.error);
+ goto error;
+ }
+
+ for (i = 0; i < argpar_parse_ret.items->n_items; i++) {
+ const struct argpar_item *item =
+ argpar_parse_ret.items->items[i];
+
+ if (item->type == ARGPAR_ITEM_TYPE_OPT) {
+ const struct argpar_item_opt *item_opt =
+ (const struct argpar_item_opt *) item;
+
+ switch (item_opt->descr->id) {
+ case OPT_HELP:
+ SHOW_HELP();
+ ret = 0;
+ goto end;
+
+ case OPT_LIST_OPTIONS:
+ list_cmd_options_argpar(stdout,
+ list_trigger_options);
+ ret = 0;
+ goto end;
+
+ default:
+ abort();
+ }
+
+ } else {
+ const struct argpar_item_non_opt *item_non_opt =
+ (const struct argpar_item_non_opt *) item;
+
+ ERR("Unexpected argument: %s", item_non_opt->arg);
+ }
+ }
+
+ ret = lttng_list_triggers(&triggers);
+ if (ret != LTTNG_OK) {
+ ERR("Error listing triggers: %s.", lttng_strerror(-ret));
+ goto error;
+ }
+
+ trigger_status = lttng_triggers_get_count(triggers, &num_triggers);
+ if (trigger_status != LTTNG_TRIGGER_STATUS_OK) {
+ ERR("Failed to get trigger count.");
+ goto error;
+ }
+
+ for (i = 0; i < num_triggers; i++) {
+ const int add_ret = lttng_dynamic_pointer_array_add_pointer(
+ &sorted_triggers,
+ (void *) lttng_triggers_get_at_index(triggers, i));
+
+ if (add_ret) {
+ ERR("Failed to allocate array of struct lttng_trigger *.");
+ goto error;
+ }
+ }
+
+ qsort(sorted_triggers.array.buffer.data, num_triggers,
+ sizeof(struct lttng_trigger *),
+ compare_triggers_by_name);
+
+ for (i = 0; i < num_triggers; i++) {
+ const struct lttng_trigger *trigger_to_print =
+ (const struct lttng_trigger *)
+ lttng_dynamic_pointer_array_get_pointer(
+ &sorted_triggers, i);
+
+ print_one_trigger(trigger_to_print);
+ }
+
+ ret = 0;
+ goto end;
+
+error:
+ ret = 1;
+
+end:
+ argpar_parse_ret_fini(&argpar_parse_ret);
+ lttng_triggers_destroy(triggers);
+ lttng_dynamic_pointer_array_reset(&sorted_triggers);
+
+ return ret;
+}
--- /dev/null
+#!/bin/bash
+#
+# Copyright (C) - 2020 EfficiOS, inc
+#
+# This library is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+# Test the `lttng list-trigger` command line interface.
+
+CURDIR="$(dirname "$0")"
+TESTDIR="$CURDIR/../../.."
+
+# shellcheck source=../../../utils/utils.sh
+source "$TESTDIR/utils/utils.sh"
+
+plan_tests 40
+
+FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
+
+tmp_stdout=$(mktemp -t test_list_triggers_cli_stdout.XXXXXX)
+tmp_stderr=$(mktemp -t test_list_triggers_cli_stderr.XXXXXX)
+tmp_expected_stdout=$(mktemp -t test_list_triggers_cli_expected_stdout.XXXXXX)
+uprobe_elf_binary=$(realpath "${TESTDIR}/utils/testapp/userspace-probe-elf-binary/.libs/userspace-probe-elf-binary")
+
+uid=$(id --user)
+gid=$(id --group)
+
+if [ "$uid" == "0" ]; then
+ ist_root=1
+else
+ ist_root=0
+fi
+
+function add_trigger ()
+{
+ "${FULL_LTTNG_BIN}" add-trigger "$@"
+ ok $? "add trigger \`$*\`: exit code is 0"
+}
+
+function list_triggers ()
+{
+ local test_name="$1"
+ local expected_stdout_file="$2"
+
+ "${FULL_LTTNG_BIN}" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}"
+ ok $? "${test_name}: exit code is 0"
+
+ diff -u "${expected_stdout_file}" "${tmp_stdout}"
+ ok $? "${test_name}: expected stdout"
+
+ diff -u /dev/null "${tmp_stderr}"
+ ok $? "${test_name}: expected stderr"
+}
+
+test_top_level_options ()
+{
+ # shellcheck disable=SC2119
+ start_lttng_sessiond_notap
+
+
+ add_trigger --id hello --condition on-event -u test-id --action notify
+ add_trigger --fire-once-after 123 --condition on-event -u test-fire-once-after --action notify
+ add_trigger --fire-every 124 --condition on-event -u test-fire-every --action notify
+
+ cat > "${tmp_expected_stdout}" <<- EOF
+ - id: T0
+ user id: ${uid}
+ firing policy: once after 123 occurences
+ condition: event rule hit
+ rule: test-fire-once-after (type: tracepoint, domain: ust)
+ actions:
+ notify
+ - id: T1
+ user id: ${uid}
+ firing policy: after every 124 occurences
+ condition: event rule hit
+ rule: test-fire-every (type: tracepoint, domain: ust)
+ actions:
+ notify
+ - id: hello
+ user id: ${uid}
+ condition: event rule hit
+ rule: test-id (type: tracepoint, domain: ust)
+ actions:
+ notify
+ EOF
+
+ list_triggers "top level options" "${tmp_expected_stdout}"
+
+ stop_lttng_sessiond_notap
+}
+
+test_on_event_tracepoint ()
+{
+ # shellcheck disable=SC2119
+ start_lttng_sessiond_notap
+
+ add_trigger --condition on-event -u -a --action notify
+ add_trigger --id ABC --condition on-event aaa -u --filter 'p == 2' --action notify
+ add_trigger --condition on-event 'hello*' -u -x 'hello2,hello3,hello4' --action notify
+ add_trigger --id BCD --condition on-event -u gerboise --loglevel INFO --action notify
+ add_trigger --condition on-event -u lemming --loglevel-only WARNING --action notify
+
+ cat > "${tmp_expected_stdout}" <<- EOF
+ - id: ABC
+ user id: ${uid}
+ condition: event rule hit
+ rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
+ actions:
+ notify
+ - id: BCD
+ user id: ${uid}
+ condition: event rule hit
+ rule: gerboise (type: tracepoint, domain: ust, log level <= TRACE_INFO)
+ actions:
+ notify
+ - id: T0
+ user id: ${uid}
+ condition: event rule hit
+ rule: * (type: tracepoint, domain: ust)
+ actions:
+ notify
+ - id: T1
+ user id: ${uid}
+ condition: event rule hit
+ rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
+ actions:
+ notify
+ - id: T2
+ user id: ${uid}
+ condition: event rule hit
+ rule: lemming (type: tracepoint, domain: ust, log level == TRACE_WARNING)
+ actions:
+ notify
+ EOF
+
+ list_triggers "on-event, tracepoint event rule" "${tmp_expected_stdout}"
+
+ stop_lttng_sessiond_notap
+}
+
+test_on_event_probe ()
+{
+ local channel_enable_addr
+ local channel_disable_addr
+
+ # shellcheck disable=SC2119
+ start_lttng_sessiond_notap
+
+ channel_enable_addr=$(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
+ channel_disable_addr=$(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
+
+ # We need to find a valid offset.
+ base_symbol=""
+ offset=0
+ if [[ 0x$channel_enable_addr -lt 0x$channel_disable_addr ]]; then
+ base_symbol="lttng_channel_enable"
+ offset=$(( 0x$channel_disable_addr - 0x$channel_enable_addr ))
+ else
+ base_symbol="lttng_channel_disable"
+ offset=$(( 0x$channel_enable_addr - 0x$channel_disable_addr ))
+ fi
+
+ offset_hex="0x$(printf '%x' $offset)"
+
+ add_trigger --condition on-event -k --probe=lttng_channel_enable my_channel_enable --action notify
+ add_trigger --condition on-event -k --probe="${base_symbol}+${offset_hex}" my_channel_enable --action notify
+ add_trigger --condition on-event -k --probe="0x${channel_enable_addr}" my_channel_enable --action notify
+
+ cat > "${tmp_expected_stdout}" <<- EOF
+ - id: T0
+ user id: ${uid}
+ condition: event rule hit
+ rule: my_channel_enable (type: probe, location: lttng_channel_enable)
+ actions:
+ notify
+ - id: T1
+ user id: ${uid}
+ condition: event rule hit
+ rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex})
+ actions:
+ notify
+ - id: T2
+ user id: ${uid}
+ condition: event rule hit
+ rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
+ actions:
+ notify
+ EOF
+
+ list_triggers "on-event, probe event rule" "${tmp_expected_stdout}"
+
+ stop_lttng_sessiond_notap
+}
+
+test_on_event_userspace_probe ()
+{
+ # shellcheck disable=SC2119
+ start_lttng_sessiond_notap
+
+ add_trigger --condition on-event -k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe --action notify
+
+ cat > "${tmp_expected_stdout}" <<- EOF
+ - id: T0
+ user id: ${uid}
+ condition: event rule hit
+ rule: ma-probe (type: userspace probe, location: ${uprobe_elf_binary}:test_function)
+ actions:
+ notify
+ EOF
+
+ list_triggers "on-event, userspace-probe event rule" "${tmp_expected_stdout}"
+
+ stop_lttng_sessiond_notap
+}
+
+test_on_event_syscall ()
+{
+ # shellcheck disable=SC2119
+ start_lttng_sessiond_notap
+
+ add_trigger --condition on-event -k --syscall open --action notify
+ add_trigger --condition on-event -k --syscall ptrace --filter 'a > 2' --action notify
+
+ cat > "${tmp_expected_stdout}" <<- EOF
+ - id: T0
+ user id: ${uid}
+ condition: event rule hit
+ rule: open (type: syscall)
+ actions:
+ notify
+ - id: T1
+ user id: ${uid}
+ condition: event rule hit
+ rule: ptrace (type: syscall, filter: a > 2)
+ actions:
+ notify
+ EOF
+
+ list_triggers "on-event, syscall event rule" "${tmp_expected_stdout}"
+
+ stop_lttng_sessiond_notap
+}
+
+test_snapshot_action ()
+{
+ start_lttng_sessiond_notap
+
+ add_trigger --condition on-event -u some-event --action snapshot-session ze-session
+ add_trigger --condition on-event -u some-event --action snapshot-session ze-session --path /some/path
+ add_trigger --condition on-event -u some-event --action snapshot-session ze-session --url file:///some/other/path
+ add_trigger --condition on-event -u some-event --action snapshot-session ze-session --url net://1.2.3.4
+ add_trigger --condition on-event -u some-event --action snapshot-session ze-session --url net://1.2.3.4:1234:1235
+ add_trigger --condition on-event -u some-event --action snapshot-session ze-session --ctrl-url=tcp://1.2.3.4:1111 --data-url=tcp://1.2.3.4:1112
+ add_trigger --condition on-event -u some-event --action snapshot-session ze-session --path /some/path --max-size=1234
+ add_trigger --condition on-event -u some-event --action snapshot-session ze-session --path /some/path --name=meh
+
+
+ cat > "${tmp_expected_stdout}" <<- EOF
+ - id: T0
+ user id: ${uid}
+ condition: event rule hit
+ rule: some-event (type: tracepoint, domain: ust)
+ actions:
+ snapshot session \`ze-session\`
+ - id: T1
+ user id: ${uid}
+ condition: event rule hit
+ rule: some-event (type: tracepoint, domain: ust)
+ actions:
+ snapshot session \`ze-session\`, path: /some/path
+ - id: T2
+ user id: ${uid}
+ condition: event rule hit
+ rule: some-event (type: tracepoint, domain: ust)
+ actions:
+ snapshot session \`ze-session\`, path: /some/other/path
+ - id: T3
+ user id: ${uid}
+ condition: event rule hit
+ rule: some-event (type: tracepoint, domain: ust)
+ actions:
+ snapshot session \`ze-session\`, url: net://1.2.3.4
+ - id: T4
+ user id: ${uid}
+ condition: event rule hit
+ rule: some-event (type: tracepoint, domain: ust)
+ actions:
+ snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
+ - id: T5
+ user id: ${uid}
+ condition: event rule hit
+ rule: some-event (type: tracepoint, domain: ust)
+ actions:
+ snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
+ - id: T6
+ user id: ${uid}
+ condition: event rule hit
+ rule: some-event (type: tracepoint, domain: ust)
+ actions:
+ snapshot session \`ze-session\`, path: /some/path, max size: 1234
+ - id: T7
+ user id: ${uid}
+ condition: event rule hit
+ rule: some-event (type: tracepoint, domain: ust)
+ actions:
+ snapshot session \`ze-session\`, path: /some/path, name: meh
+ EOF
+
+ list_triggers "snapshot action" "${tmp_expected_stdout}"
+
+ stop_lttng_sessiond_notap
+}
+
+test_top_level_options
+test_on_event_tracepoint
+skip $ist_root "non-root user: skipping kprobe tests" 6 || test_on_event_probe
+skip $ist_root "non-root user: skipping uprobe tests" 4 || test_on_event_userspace_probe
+skip $ist_root "non-root user: skipping syscall tests" 5 || test_on_event_syscall
+test_snapshot_action
+
+# Cleanup
+rm -f "${tmp_stdout}"
+rm -f "${tmp_stderr}"
+rm -f "${tmp_expected_stdout}"