]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
kqueue: Enable kqueue debugging with debug level, not blindly at the start of every...
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 20 May 2023 16:00:09 +0000 (12:00 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 20 May 2023 16:49:50 +0000 (12:49 -0400)
.github/workflows/ci-macos.yml
.github/workflows/ci-sanitizers.yml
.github/workflows/ci-scheduled-fuzzing.yml
.github/workflows/ci.yml
scripts/ci/startservice.sh
src/lib/util/event.c

index fa0129a164604732b5329c0c65b87e36ad25ae17..a8e878ac921d261628958f2b9641d1fe6791b193 100644 (file)
@@ -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
index 6d5ab6d6c52a892249dafa1d081045c95710283a..d984599e01458d4a4c98527f27dce69c72b02f64 100644 (file)
@@ -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
index 441432672a7c9f45bf63cb28ce8897001c0a6448..2177bf4433ba0342d54e25ac98921e6aa02b3376 100644 (file)
@@ -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
index 697dbdb9133012e137f0c4b77c0d22af6a7c4f61..8ebcf2017acba38194b8d6416513e60e475fcb06 100644 (file)
@@ -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
index fff845bdd07d0d478125d7bbc353d973b1e7fb60..894eda6afa646d2a5caa8119cc61ce09256f0c1d 100644 (file)
@@ -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"
index 5639b386471ade02e3b8582c1d373057ff16fcf9..ba03c7f335bdeafe9c7aa40088336cbf552f57f3 100644 (file)
@@ -32,6 +32,7 @@ RCSID("$Id$")
 #include <freeradius-devel/util/dlist.h>
 #include <freeradius-devel/util/event.h>
 #include <freeradius-devel/util/lst.h>
+#include <freeradius-devel/util/log.h>
 #include <freeradius-devel/util/rb.h>
 #include <freeradius-devel/util/strerror.h>
 #include <freeradius-devel/util/syserror.h>
@@ -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)) {