From 64f30f5480fef88edb8f633ffecdbc181f0a6900 Mon Sep 17 00:00:00 2001 From: Ambroz Bizjak Date: Wed, 17 Aug 2016 21:34:21 +0200 Subject: Fix usage of sigprocmask() to pthread_sigmask(). --- system/BProcess.c | 8 ++++---- system/BUnixSignal.c | 17 +++++++++-------- system/BUnixSignal.h | 4 ++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/system/BProcess.c b/system/BProcess.c index 368db4e..19c5ac1 100644 --- a/system/BProcess.c +++ b/system/BProcess.c @@ -274,8 +274,8 @@ int BProcess_Init2 (BProcess *o, BProcessManager *m, BProcess_handler handler, v sigset_t sset_all; sigfillset(&sset_all); sigset_t sset_old; - if (sigprocmask(SIG_SETMASK, &sset_all, &sset_old) < 0) { - BLog(BLOG_ERROR, "sigprocmask failed"); + if (pthread_sigmask(SIG_SETMASK, &sset_all, &sset_old) != 0) { + BLog(BLOG_ERROR, "pthread_sigmask failed"); goto fail3; } @@ -297,7 +297,7 @@ int BProcess_Init2 (BProcess *o, BProcessManager *m, BProcess_handler handler, v // unblock signals sigset_t sset_none; sigemptyset(&sset_none); - if (sigprocmask(SIG_SETMASK, &sset_none, NULL) < 0) { + if (pthread_sigmask(SIG_SETMASK, &sset_none, NULL) != 0) { abort(); } @@ -365,7 +365,7 @@ int BProcess_Init2 (BProcess *o, BProcessManager *m, BProcess_handler handler, v } // restore original signal mask - ASSERT_FORCE(sigprocmask(SIG_SETMASK, &sset_old, NULL) == 0) + ASSERT_FORCE(pthread_sigmask(SIG_SETMASK, &sset_old, NULL) == 0) if (pid < 0) { BLog(BLOG_ERROR, "fork failed"); diff --git a/system/BUnixSignal.c b/system/BUnixSignal.c index 94edd6b..d24655d 100644 --- a/system/BUnixSignal.c +++ b/system/BUnixSignal.c @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef BADVPN_USE_SIGNALFD #include @@ -189,8 +190,8 @@ int BUnixSignal_Init (BUnixSignal *o, BReactor *reactor, sigset_t signals, BUnix BReactor_SetFileDescriptorEvents(o->reactor, &o->signalfd_bfd, BREACTOR_READ); // block signals - if (sigprocmask(SIG_BLOCK, &o->signals, 0) < 0) { - BLog(BLOG_ERROR, "sigprocmask block failed"); + if (pthread_sigmask(SIG_BLOCK, &o->signals, 0) != 0) { + BLog(BLOG_ERROR, "pthread_sigmask block failed"); goto fail2; } @@ -230,8 +231,8 @@ int BUnixSignal_Init (BUnixSignal *o, BReactor *reactor, sigset_t signals, BUnix } // block signals - if (sigprocmask(SIG_BLOCK, &o->signals, 0) < 0) { - BLog(BLOG_ERROR, "sigprocmask block failed"); + if (pthread_sigmask(SIG_BLOCK, &o->signals, 0) != 0) { + BLog(BLOG_ERROR, "pthread_sigmask block failed"); goto fail2; } @@ -355,7 +356,7 @@ void BUnixSignal_Free (BUnixSignal *o, int unblock) if (unblock) { // unblock signals - ASSERT_FORCE(sigprocmask(SIG_UNBLOCK, &o->signals, 0) == 0) + ASSERT_FORCE(pthread_sigmask(SIG_UNBLOCK, &o->signals, 0) == 0) } // free signalfd BFileDescriptor @@ -370,7 +371,7 @@ void BUnixSignal_Free (BUnixSignal *o, int unblock) if (unblock) { // unblock signals - ASSERT_FORCE(sigprocmask(SIG_UNBLOCK, &o->signals, 0) == 0) + ASSERT_FORCE(pthread_sigmask(SIG_UNBLOCK, &o->signals, 0) == 0) } // free kevents @@ -388,8 +389,8 @@ void BUnixSignal_Free (BUnixSignal *o, int unblock) if (!unblock) { // block signals - if (sigprocmask(SIG_BLOCK, &o->signals, 0) < 0) { - BLog(BLOG_ERROR, "sigprocmask block failed"); + if (pthread_sigmask(SIG_BLOCK, &o->signals, 0) != 0) { + BLog(BLOG_ERROR, "pthread_sigmask block failed"); } } diff --git a/system/BUnixSignal.h b/system/BUnixSignal.h index 2438be9..c7aa389 100644 --- a/system/BUnixSignal.h +++ b/system/BUnixSignal.h @@ -106,7 +106,7 @@ typedef struct BUnixSignal_s { * WARNING: for every signal number there should be at most one {@link BUnixSignal} * object handling it (or anything else that could interfere). * - * This blocks the signal using sigprocmask() and sets up signalfd() for receiving + * This blocks the signal using pthread_sigmask() and sets up signalfd() for receiving * signals. * * @param o the object @@ -122,7 +122,7 @@ int BUnixSignal_Init (BUnixSignal *o, BReactor *reactor, sigset_t signals, BUnix * Frees the object. * * @param o the object - * @param unblock whether to unblock the signals using sigprocmask(). Not unblocking it + * @param unblock whether to unblock the signals using pthread_sigmask(). Not unblocking it * can be used while the program is exiting gracefully to prevent the * signals from being handled handled according to its default disposition * after this function is called. Must be 0 or 1. -- cgit v1.2.3