From: Arran Cudbard-Bell Date: Sat, 20 May 2023 16:00:09 +0000 (-0400) Subject: kqueue: Enable kqueue debugging with debug level, not blindly at the start of every... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6bff35432afe93027c313a4a1ac7a33f653d65ff;p=thirdparty%2Ffreeradius-server.git kqueue: Enable kqueue debugging with debug level, not blindly at the start of every CI run --- diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index fa0129a1646..a8e878ac921 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -12,7 +12,6 @@ env: ASAN_OPTIONS: symbolize=1 detect_leaks=1 detect_stack_use_after_return=1 LSAN_OPTIONS: fast_unwind_on_malloc=0:malloc_context_size=50 UBSAN_OPTIONS: print_stacktrace=1 - KQUEUE_DEBUG: yes M_PERTURB: "0x42" PANIC_ACTION: "gdb -batch -x raddb/panic.gdb %e %p 1>&0 2>&0" ANALYZE_C_DUMP: 1 diff --git a/.github/workflows/ci-sanitizers.yml b/.github/workflows/ci-sanitizers.yml index 6d5ab6d6c52..d984599e014 100644 --- a/.github/workflows/ci-sanitizers.yml +++ b/.github/workflows/ci-sanitizers.yml @@ -12,7 +12,6 @@ env: ASAN_OPTIONS: symbolize=1 detect_leaks=1 detect_stack_use_after_return=1 LSAN_OPTIONS: fast_unwind_on_malloc=0:malloc_context_size=50 UBSAN_OPTIONS: print_stacktrace=1 - KQUEUE_DEBUG: yes M_PERTURB: "0x42" PANIC_ACTION: "gdb -batch -x raddb/panic.gdb %e %p 1>&0 2>&0" # Stops the utilities forking on every call to check if they're running under GDB/LLDB diff --git a/.github/workflows/ci-scheduled-fuzzing.yml b/.github/workflows/ci-scheduled-fuzzing.yml index 441432672a7..2177bf4433b 100644 --- a/.github/workflows/ci-scheduled-fuzzing.yml +++ b/.github/workflows/ci-scheduled-fuzzing.yml @@ -47,7 +47,6 @@ on: env: ASAN_OPTIONS: symbolize=1 detect_leaks=1 detect_stack_use_after_return=1 LSAN_OPTIONS: fast_unwind_on_malloc=0:malloc_context_size=50 - KQUEUE_DEBUG: yes M_PERTURB: "0x42" PANIC_ACTION: "gdb -batch -x raddb/panic.gdb %e %p 1>&0 2>&0" ANALYZE_C_DUMP: 1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 697dbdb9133..8ebcf2017ac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,6 @@ env: ASAN_OPTIONS: symbolize=1 detect_leaks=1 detect_stack_use_after_return=1 LSAN_OPTIONS: fast_unwind_on_malloc=0:malloc_context_size=50 UBSAN_OPTIONS: print_stacktrace=1 - KQUEUE_DEBUG: yes M_PERTURB: "0x42" PANIC_ACTION: "gdb -batch -x raddb/panic.gdb %e %p 1>&0 2>&0" # Stops the utilities forking on every call to check if they're running under GDB/LLDB diff --git a/scripts/ci/startservice.sh b/scripts/ci/startservice.sh index fff845bdd07..894eda6afa6 100644 --- a/scripts/ci/startservice.sh +++ b/scripts/ci/startservice.sh @@ -30,7 +30,6 @@ function run-tests() { ### set global environment variables export ASAN_OPTIONS="symbolize=1 detect_leaks=1 detect_stack_use_after_return=1" export LSAN_OPTIONS="fast_unwind_on_malloc=0:malloc_context_size=50" - export KQUEUE_DEBUG="yes" export M_PERTURB=0x42 export PANIC_ACTION="gdb -batch -x raddb/panic.gdb %e %p" export SQL_MYSQL_TEST_SERVER="127.0.0.1" diff --git a/src/lib/util/event.c b/src/lib/util/event.c index 5639b386471..ba03c7f335b 100644 --- a/src/lib/util/event.c +++ b/src/lib/util/event.c @@ -32,6 +32,7 @@ RCSID("$Id$") #include #include #include +#include #include #include #include @@ -91,6 +92,10 @@ static fr_table_num_sorted_t const kevent_filter_table[] = { }; static size_t kevent_filter_table_len = NUM_ELEMENTS(kevent_filter_table); +#ifdef __linux__ +static int log_conf_kq; +#endif + /** A timer event * */ @@ -2812,6 +2817,68 @@ static int _event_build_indexes(UNUSED void *uctx) return 0; } +#ifdef __linux__ +/** kqueue logging wrapper function + * + */ +static CC_HINT(format (printf, 1, 2)) CC_HINT(nonnull) +void _event_kqueue_log(char const *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + fr_vlog(&default_log, L_DBG, __FILE__, __LINE__, fmt, ap); + va_end(ap); +} + +/** If we're building with libkqueue, and at debug level 4 or higher, enable libkqueue debugging output + * + * This requires a debug build of libkqueue + */ +static int _event_kqueue_logging(UNUSED void *uctx) +{ + struct kevent kev, receipt; + + log_conf_kq = kqueue(); + if (unlikely(log_conf_kq < 0)) { + fr_strerror_const("Failed initialising logging configuration kqueue"); + return -1; + } + + EV_SET(&kev, 0, EVFILT_LIBKQUEUE, EV_ADD, NOTE_DEBUG_FUNC, (intptr_t)_event_kqueue_log, NULL); + if (kevent(log_conf_kq, &kev, 1, &receipt, 1, &(struct timespec){}) != 1) { + close(log_conf_kq); + log_conf_kq = -1; + return 1; + } + + if (fr_debug_lvl >= L_DBG_LVL_3) { + EV_SET(&kev, 0, EVFILT_LIBKQUEUE, EV_ADD, NOTE_DEBUG, 1, NULL); + if (kevent(log_conf_kq, &kev, 1, &receipt, 1, &(struct timespec){}) != 1) { + fr_strerror_const("Failed enabling libkqueue debug logging"); + close(log_conf_kq); + log_conf_kq = -1; + return -1; + } + } + + return 0; +} + +static int _event_kqueue_logging_stop(UNUSED void *uctx) +{ + struct kevent kev, receipt; + + EV_SET(&kev, 0, EVFILT_LIBKQUEUE, EV_ADD, NOTE_DEBUG_FUNC, 0, NULL); + (void)kevent(log_conf_kq, &kev, 1, &receipt, 1, &(struct timespec){}); + + close(log_conf_kq); + log_conf_kq = -1; + + return 0; +} +#endif + /** Initialise a new event list * * @param[in] ctx to allocate memory in. @@ -2832,6 +2899,9 @@ fr_event_list_t *fr_event_list_alloc(TALLOC_CTX *ctx, fr_event_status_cb_t statu * function is called. */ fr_atexit_global_once_ret(&ret, _event_build_indexes, _event_free_indexes, NULL); +#ifdef __linux__ + fr_atexit_global_once_ret(&ret, _event_kqueue_logging, _event_kqueue_logging_stop, NULL); +#endif el = talloc_zero(ctx, fr_event_list_t); if (!fr_cond_assert(el)) {