diff --git a/common.cpp b/common.cpp index 437a022e9..cf77d1e2a 100644 --- a/common.cpp +++ b/common.cpp @@ -623,9 +623,9 @@ int read_blocked(int fd, void *buf, size_t count) sigemptyset( &chldset ); sigaddset( &chldset, SIGCHLD ); - sigprocmask(SIG_BLOCK, &chldset, &oldset); + VOMIT_ON_FAILURE(pthread_sigmask(SIG_BLOCK, &chldset, &oldset)); res = read( fd, buf, count ); - sigprocmask( SIG_SETMASK, &oldset, 0 ); + VOMIT_ON_FAILURE(pthread_sigmask(SIG_SETMASK, &oldset, NULL)); return res; } diff --git a/iothread.cpp b/iothread.cpp index 7c6132c32..3665df302 100644 --- a/iothread.cpp +++ b/iothread.cpp @@ -96,12 +96,7 @@ static ThreadedRequest_t *dequeue_request(void) { static void *iothread_worker(void *threadPtr) { assert(threadPtr != NULL); struct WorkerThread_t *thread = (struct WorkerThread_t *)threadPtr; - - // We don't want to receive signals on this thread - sigset_t set; - sigfillset(&set); - VOMIT_ON_FAILURE(pthread_sigmask(SIG_SETMASK, &set, NULL)); - + /* Grab a request off of the queue */ struct ThreadedRequest_t *req = dequeue_request(); @@ -124,7 +119,12 @@ static void iothread_spawn_if_needed(void) { struct WorkerThread_t *thread = next_vacant_thread_slot(); assert(thread != NULL); - /* Spawn a thread */ + /* The spawned thread inherits our signal mask. We don't want the thread to ever receive signals on the spawned thread, so temporarily block all signals, spawn the thread, and then restore it. */ + sigset_t newSet, savedSet; + sigfillset(&newSet); + VOMIT_ON_FAILURE(pthread_sigmask(SIG_BLOCK, &newSet, &savedSet)); + + /* Spawn a thread. */ int err; do { err = 0; @@ -132,10 +132,15 @@ static void iothread_spawn_if_needed(void) { err = errno; } } while (err == EAGAIN); + + /* Need better error handling - perhaps try again later. */ assert(err == 0); /* Note that we are spawned another thread */ - s_active_thread_count += 1; + s_active_thread_count += 1; + + /* Restore our sigmask */ + VOMIT_ON_FAILURE(pthread_sigmask(SIG_SETMASK, &savedSet, NULL)); } } diff --git a/signal.cpp b/signal.cpp index 810e6a297..2e132c8db 100644 --- a/signal.cpp +++ b/signal.cpp @@ -636,7 +636,7 @@ void signal_block() if( !block_count ) { sigfillset( &chldset ); - sigprocmask(SIG_BLOCK, &chldset, 0); + VOMIT_ON_FAILURE(pthread_sigmask(SIG_BLOCK, &chldset, NULL)); } block_count++; @@ -660,7 +660,7 @@ void signal_unblock() if( !block_count ) { sigfillset( &chldset ); - sigprocmask(SIG_UNBLOCK, &chldset, 0); + VOMIT_ON_FAILURE(pthread_sigmask(SIG_UNBLOCK, &chldset, 0)); } // debug( 0, L"signal block level decreased to %d", block_count ); }