From 3022236e47c0c89b19cf0ecac4b649ca8448cf65 Mon Sep 17 00:00:00 2001 From: Arran Cudbard-Bell Date: Mon, 13 May 2024 13:44:51 -0600 Subject: [PATCH] Make cntrl-c work again on macOS, after we do a TLS handhshake --- src/lib/io/schedule.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/lib/io/schedule.c b/src/lib/io/schedule.c index abdbe8cbf8dde..418c9ccee5783 100644 --- a/src/lib/io/schedule.c +++ b/src/lib/io/schedule.c @@ -172,6 +172,22 @@ static void *fr_schedule_worker_thread(void *arg) fr_schedule_child_status_t status = FR_CHILD_FAIL; fr_schedule_network_t *sn; char worker_name[32]; + +#ifndef __APPLE__ + /* + * This ifdef is because macOS doesn't use pthread_signmask in its + * setcontext function, and seems to apply the signal mask of the thread + * to the entire process when setcontext is called. + * + * * frame #0: 0x00000001934118b0 libsystem_kernel.dylib`sigprocmask + * frame #1: 0x0000000193481f3c libsystem_platform.dylib`setcontext + 44 + * frame #2: 0x0000000100f27298 libcrypto.3.dylib`async_fibre_swapcontext + 52 + * frame #3: 0x0000000100f274a0 libcrypto.3.dylib`ASYNC_start_job + 496 + * frame #4: 0x0000000100b17884 libssl.3.dylib`ssl_start_async_job + 116 + * frame #5: 0x0000000100b17804 libssl.3.dylib`ssl_read_internal + 356 + * frame #6: 0x0000000100b17a0c libssl.3.dylib`SSL_read + 28 + * frame #7: 0x00000001004f5b94 libfreeradius-tls.dylib`tls_session_async_handshake_cont(p_result=0x0000000112815c7c, priority=0x0000000112815edc, request=0x0000000112815a80, uctx=0x0000000139160060) at session.c:1366:26 + */ sigset_t sigset; sigfillset(&sigset); @@ -182,6 +198,7 @@ static void *fr_schedule_worker_thread(void *arg) * idle, so they can handle signals. */ pthread_sigmask(SIG_BLOCK, &sigset, NULL); +#endif worker_id = sw->id; /* Store the current worker ID */ @@ -303,16 +320,33 @@ static void *fr_schedule_network_thread(void *arg) fr_schedule_child_status_t status = FR_CHILD_FAIL; fr_event_list_t *el; char network_name[32]; + +#ifndef __APPLE__ + /* + * This ifdef is because macOS doesn't use pthread_signmask in its + * setcontext function, and seems to apply the signal mask of the thread + * to the entire process when setcontext is called. + * + * * frame #0: 0x00000001934118b0 libsystem_kernel.dylib`sigprocmask + * frame #1: 0x0000000193481f3c libsystem_platform.dylib`setcontext + 44 + * frame #2: 0x0000000100f27298 libcrypto.3.dylib`async_fibre_swapcontext + 52 + * frame #3: 0x0000000100f274a0 libcrypto.3.dylib`ASYNC_start_job + 496 + * frame #4: 0x0000000100b17884 libssl.3.dylib`ssl_start_async_job + 116 + * frame #5: 0x0000000100b17804 libssl.3.dylib`ssl_read_internal + 356 + * frame #6: 0x0000000100b17a0c libssl.3.dylib`SSL_read + 28 + * frame #7: 0x00000001004f5b94 libfreeradius-tls.dylib`tls_session_async_handshake_cont(p_result=0x0000000112815c7c, priority=0x0000000112815edc, request=0x0000000112815a80, uctx=0x0000000139160060) at session.c:1366:26 + */ sigset_t sigset; sigfillset(&sigset); /* - * Ensure network threads aren't interrupted by - * signals. The main thread, and main event loop - * are mostly idle, so they can handle signals. + * Ensure workers aren't interrupted by signals. + * The main thread, and main event loop are mostly + * idle, so they can handle signals. */ pthread_sigmask(SIG_BLOCK, &sigset, NULL); +#endif snprintf(network_name, sizeof(network_name), "Network %d", sn->id);