summaryrefslogtreecommitdiffstats
path: root/lib/frr_pthread.c
diff options
context:
space:
mode:
authorMark Stapp <mjs@voltanet.io>2020-07-09 17:21:10 +0200
committerMark Stapp <mjs@voltanet.io>2020-07-09 17:21:10 +0200
commitf4635e33a62d6f30339a5d0cfdbfaa90fba1f8df (patch)
treec0ff4a1559c536095bd9d5eb867c2aae4640f658 /lib/frr_pthread.c
parentMerge pull request #6697 from donaldsharp/ospf_router_id_ordering (diff)
downloadfrr-f4635e33a62d6f30339a5d0cfdbfaa90fba1f8df.tar.xz
frr-f4635e33a62d6f30339a5d0cfdbfaa90fba1f8df.zip
lib: block signals in child pthreads
Block signals in child/additional pthreads; frr daemons generally expect that only the main thread will handle signals. Signed-off-by: Mark Stapp <mjs@voltanet.io>
Diffstat (limited to 'lib/frr_pthread.c')
-rw-r--r--lib/frr_pthread.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c
index e237934f8..da9594ed8 100644
--- a/lib/frr_pthread.c
+++ b/lib/frr_pthread.c
@@ -159,10 +159,20 @@ static void *frr_pthread_inner(void *arg)
int frr_pthread_run(struct frr_pthread *fpt, const pthread_attr_t *attr)
{
int ret;
+ sigset_t oldsigs, blocksigs;
+
+ /* Ensure we never handle signals on a background thread by blocking
+ * everything here (new thread inherits signal mask)
+ */
+ sigfillset(&blocksigs);
+ pthread_sigmask(SIG_BLOCK, &blocksigs, &oldsigs);
fpt->rcu_thread = rcu_thread_prepare();
ret = pthread_create(&fpt->thread, attr, frr_pthread_inner, fpt);
+ /* Restore caller's signals */
+ pthread_sigmask(SIG_SETMASK, &oldsigs, NULL);
+
/*
* Per pthread_create(3), the contents of fpt->thread are undefined if
* pthread_create() did not succeed. Reset this value to zero.