Skip to content

Commit

Permalink
Make cntrl-c work again on macOS, after we do a TLS handhshake
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed May 13, 2024
1 parent 33c5909 commit 3022236
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions src/lib/io/schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 */

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 3022236

Please sign in to comment.