summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGuillaume Solignac <gsoligna@cisco.com>2024-05-22 10:47:33 +0200
committerDamjan Marion <dmarion@0xa5.net>2024-05-22 12:52:31 +0000
commit5444973bd08ff8e9a103fb3436adbdcbb2f666b8 (patch)
tree80f9670f6d08222339be6cbf4c0bcb10c818fe28 /src
parent71e0902454a2dd51f2ef0526f26ac1c37bf81686 (diff)
vlib: prevent some signals from being executed on workers
Before this commit, SIGINT, SIGHUP and SIGTERM could be executed on the workers. Since those signals don't stop execution, it meant that atexit handlers (like the `vl_unmap_shmem`) could run while the main thread was still running, which can cause race conditions. To avoid that, we prevent workers from handling those signals. Type: fix Signed-off-by: Guillaume Solignac <gsoligna@cisco.com> Change-Id: I27a87d96a027d7423ced881a614427af4ab0f969
Diffstat (limited to 'src')
-rw-r--r--src/vlib/threads.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/vlib/threads.c b/src/vlib/threads.c
index 87b71adc2bc..854d69448ac 100644
--- a/src/vlib/threads.c
+++ b/src/vlib/threads.c
@@ -370,6 +370,8 @@ void
vlib_worker_thread_init (vlib_worker_thread_t * w)
{
vlib_thread_main_t *tm = vlib_get_thread_main ();
+ sigset_t signals;
+ int rv;
/*
* Note: disabling signals in worker threads as follows
@@ -379,7 +381,17 @@ vlib_worker_thread_init (vlib_worker_thread_t * w)
* sigfillset (&s);
* pthread_sigmask (SIG_SETMASK, &s, 0);
* }
+ * We can still disable signals for SIGINT,SIGHUP and SIGTERM as they don't
+ * trigger post-dump handlers anyway.
*/
+ sigemptyset (&signals);
+ sigaddset (&signals, SIGINT);
+ sigaddset (&signals, SIGHUP);
+ sigaddset (&signals, SIGTERM);
+ rv = pthread_sigmask (SIG_BLOCK, &signals, NULL);
+
+ if (rv)
+ clib_warning ("Failed to set the worker signal mask");
clib_mem_set_heap (w->thread_mheap);