From 496fc78f6385ad394825c2923d6efa95f30faa77 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Wed, 12 May 2021 11:28:26 -0400 Subject: [PATCH] Fix: trigger: abort() when adding `--notify` action with python event rule matches MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Issue ===== Adding the following trigger makes the sessiond abort: lttng add-trigger --condition=event-rule-matches --domain=python --action=notify With the following stacktrace: (gdb) bt #0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50 #1 0x00007ffff7a71859 in __GI_abort () at abort.c:79 #2 0x00000000004a1eeb in event_notifier_error_accounting_register_event_notifier (trigger=0x7fffe0000f50, error_counter_index=0x7fffefffde38) at event-notifier-error-accounting.c:1075 #3 0x00000000004743e6 in setup_tracer_notifier (state=0x7fffefffe3e8, trigger=0x7fffe0000f50) at notification-thread-events.c:2606 #4 0x000000000046dacb in handle_notification_thread_command_register_trigger (state=0x7fffefffe3e8, trigger=0x7fffe0000f50, is_trigger_anonymous=false, cmd_result=0x7fffedfdd6e8) at notification-thread-events.c:2751 #5 0x000000000046d083 in handle_notification_thread_command (handle=0x601460, state=0x7fffefffe3e8) at notification-thread-events.c:3112 #6 0x00000000004687bd in thread_notification (data=0x601460) at notification-thread.c:710 #7 0x0000000000486703 in launch_thread (data=0x601550) at thread.c:66 #8 0x00007ffff7c47609 in start_thread (arg=) at pthread_create.c:477 #9 0x00007ffff7b6e293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95 This happens because the LTTNG_DOMAIN_PYTHON domain is not handled by the switch-case. Fix === Add LTTNG_DOMAIN_PYTHON (all other agent domains) as a fallthrough LTTNG_DOMAIN_UST. Note ==== Add a basic test case for python agent. Signed-off-by: Francis Deslauriers Signed-off-by: Jérémie Galarneau Change-Id: I9971cdad8bbc6adca8f6ba49964483c42a25be7d --- .../event-notifier-error-accounting.c | 15 +++++++++ tests/regression/tools/trigger/Makefile.am | 1 + .../ust/python-logging/test_python_logging.in | 31 ++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/bin/lttng-sessiond/event-notifier-error-accounting.c b/src/bin/lttng-sessiond/event-notifier-error-accounting.c index 74b15bf98..e7b2def91 100644 --- a/src/bin/lttng-sessiond/event-notifier-error-accounting.c +++ b/src/bin/lttng-sessiond/event-notifier-error-accounting.c @@ -1081,6 +1081,9 @@ event_notifier_error_accounting_register_event_notifier( state = &kernel_state; break; case LTTNG_DOMAIN_UST: + case LTTNG_DOMAIN_PYTHON: + case LTTNG_DOMAIN_JUL: + case LTTNG_DOMAIN_LOG4J: state = &ust_state; break; default: @@ -1129,6 +1132,9 @@ event_notifier_error_accounting_register_event_notifier( #ifdef HAVE_LIBLTTNG_UST_CTL switch (lttng_trigger_get_underlying_domain_type_restriction(trigger)) { case LTTNG_DOMAIN_UST: + case LTTNG_DOMAIN_PYTHON: + case LTTNG_DOMAIN_JUL: + case LTTNG_DOMAIN_LOG4J: pthread_mutex_lock(&the_event_notifier_counter.lock); the_event_notifier_counter.count++; if (the_event_notifier_counter.count == 1) { @@ -1218,6 +1224,9 @@ event_notifier_error_accounting_get_count( return event_notifier_error_accounting_kernel_get_count( trigger, count); case LTTNG_DOMAIN_UST: + case LTTNG_DOMAIN_PYTHON: + case LTTNG_DOMAIN_JUL: + case LTTNG_DOMAIN_LOG4J: #ifdef HAVE_LIBLTTNG_UST_CTL return event_notifier_error_accounting_ust_get_count(trigger, count); @@ -1238,6 +1247,9 @@ event_notifier_error_accounting_clear(const struct lttng_trigger *trigger) case LTTNG_DOMAIN_KERNEL: return event_notifier_error_accounting_kernel_clear(trigger); case LTTNG_DOMAIN_UST: + case LTTNG_DOMAIN_PYTHON: + case LTTNG_DOMAIN_JUL: + case LTTNG_DOMAIN_LOG4J: #ifdef HAVE_LIBLTTNG_UST_CTL return event_notifier_error_accounting_ust_clear(trigger); #else @@ -1281,6 +1293,9 @@ void event_notifier_error_accounting_unregister_event_notifier( break; #ifdef HAVE_LIBLTTNG_UST_CTL case LTTNG_DOMAIN_UST: + case LTTNG_DOMAIN_PYTHON: + case LTTNG_DOMAIN_JUL: + case LTTNG_DOMAIN_LOG4J: state = &ust_state; pthread_mutex_lock(&the_event_notifier_counter.lock); diff --git a/tests/regression/tools/trigger/Makefile.am b/tests/regression/tools/trigger/Makefile.am index 0309f769d..fe5dd9744 100644 --- a/tests/regression/tools/trigger/Makefile.am +++ b/tests/regression/tools/trigger/Makefile.am @@ -3,6 +3,7 @@ SUBDIRS=utils start-stop rate-policy name noinst_SCRIPTS = test_add_trigger_cli \ test_list_triggers_cli \ test_remove_trigger_cli + EXTRA_DIST = test_add_trigger_cli \ test_list_triggers_cli \ test_remove_trigger_cli diff --git a/tests/regression/ust/python-logging/test_python_logging.in b/tests/regression/ust/python-logging/test_python_logging.in index 342bac2f6..4d9cbe376 100755 --- a/tests/regression/ust/python-logging/test_python_logging.in +++ b/tests/regression/ust/python-logging/test_python_logging.in @@ -25,7 +25,7 @@ run_test=@RUN_PYTHON_AGENT_TEST@ if [[ -z "$run_test" ]]; then NUM_TESTS=1 else - NUM_TESTS=$(((194 * ${#python_versions[@]})+2)) + NUM_TESTS=$(((199 * ${#python_versions[@]})+2)) fi source $TESTDIR/utils/utils.sh @@ -685,6 +685,34 @@ function test_python_filter_loglevel() fi } +function test_python_trigger_notify_action +{ + uid=$(id --user) + tmp_expected_stdout=$(mktemp -t test_list_triggers_python_cli_expected_stdout.XXXXXX) + + diag "Test Python trigger with notify action" + + lttng_add_trigger_ok "my_python_trigger" \ + --condition event-rule-matches --domain=python --action notify + + cat > "${tmp_expected_stdout}" <<- EOF + - name: my_python_trigger + owner uid: ${uid} + condition: event rule matches + rule: * (type: tracepoint, domain: python) + actions: + notify + errors: none + errors: none + EOF + + list_triggers_matches_ok "Python trigger listing" "${tmp_expected_stdout}" + + lttng_remove_trigger_ok "my_python_trigger" + + rm -f "${tmp_expected_stdout}" +} + plan_tests $NUM_TESTS print_test_banner "$TEST_DESC" @@ -717,6 +745,7 @@ skip $skip_agent "Python agent test skipped." $NUM_TESTS || test_python_after_start test_python_multi_session test_python_filter_loglevel + test_python_trigger_notify_action ) -- 2.34.1