Bladeren bron

Fix usage of sigprocmask() to pthread_sigmask().

Ambroz Bizjak 9 jaren geleden
bovenliggende
commit
64f30f5480
3 gewijzigde bestanden met toevoegingen van 15 en 14 verwijderingen
  1. 4 4
      system/BProcess.c
  2. 9 8
      system/BUnixSignal.c
  3. 2 2
      system/BUnixSignal.h

+ 4 - 4
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");

+ 9 - 8
system/BUnixSignal.c

@@ -33,6 +33,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <string.h>
+#include <signal.h>
 
 #ifdef BADVPN_USE_SIGNALFD
 #include <sys/signalfd.h>
@@ -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");
         }
     }
     

+ 2 - 2
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.