Fix: trigger: abort() when adding `--notify` action with python event rule matches
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Wed, 12 May 2021 15:28:26 +0000 (11:28 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 14 May 2021 18:10:22 +0000 (14:10 -0400)
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=<optimized out>) 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 <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I9971cdad8bbc6adca8f6ba49964483c42a25be7d

src/bin/lttng-sessiond/event-notifier-error-accounting.c
tests/regression/tools/trigger/Makefile.am
tests/regression/ust/python-logging/test_python_logging.in

index 74b15bf98a655c397436dbad532ca931d7493499..e7b2def91c4b2675d7500c6c8c664e39e1339fb6 100644 (file)
@@ -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);
index 0309f769d4a3a661515cab07c248d84c7ebfeec8..fe5dd974445a62581b05cacddd4da03ffd4e3ce9 100644 (file)
@@ -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
index 342bac2f65ca8b56105011d808e18eb1636a4861..4d9cbe37646d51fe297e27dc06c5869e4c6f0fd6 100755 (executable)
@@ -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
        )
 
 
This page took 0.027969 seconds and 4 git commands to generate.