]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: block signals in child pthreads 6704/head
authorMark Stapp <mjs@voltanet.io>
Thu, 9 Jul 2020 15:21:10 +0000 (11:21 -0400)
committerMark Stapp <mjs@voltanet.io>
Thu, 9 Jul 2020 15:21:10 +0000 (11:21 -0400)
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>
lib/frr_pthread.c

index e237934f815891d7d023600103c5f737f8afd7a2..da9594ed808c12d9f3b34ad33d5bee085ad902ed 100644 (file)
@@ -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.