]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: signals: ha_sigmask macro for multithreading
authorWilliam Lallemand <wlallemand@haproxy.com>
Thu, 7 Jun 2018 09:23:40 +0000 (11:23 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 8 Jun 2018 16:24:53 +0000 (18:24 +0200)
The behavior of sigprocmask in an multithreaded environment is
undefined.

The new macro ha_sigmask() calls either pthreads_sigmask() or
sigprocmask() if haproxy was built with thread support or not.

This should be backported to 1.8.

include/common/hathreads.h
src/checks.c
src/haproxy.c
src/signal.c

index c25f691023cdec30303b376435e0f6c91c4a79ef..5c4ceca7c1383ef1a539f63d08f8187425b69494 100644 (file)
@@ -108,6 +108,9 @@ extern THREAD_LOCAL unsigned long tid_bit; /* The bit corresponding to the threa
 #define HA_RWLOCK_TRYRDLOCK(lbl, l)   ({ 0; })
 #define HA_RWLOCK_RDUNLOCK(lbl, l) do { /* do nothing */ } while(0)
 
+#define ha_sigmask(how, set, oldset)  sigprocmask(how, set, oldset)
+
+
 static inline void __ha_barrier_load(void)
 {
 }
@@ -259,6 +262,9 @@ int  thread_need_sync(void);
 
 extern unsigned long all_threads_mask;
 
+#define ha_sigmask(how, set, oldset)  pthread_sigmask(how, set, oldset)
+
+
 #if defined(DEBUG_THREAD) || defined(DEBUG_FULL)
 
 /* WARNING!!! if you update this enum, please also keep lock_label() up to date below */
index 3f4c0e1b39bb718c2570e32b21b0970971126efd..3cae94d517d1d5debbfb9bccbb913bfa402a5cb3 100644 (file)
@@ -1618,7 +1618,7 @@ void block_sigchld(void)
        sigset_t set;
        sigemptyset(&set);
        sigaddset(&set, SIGCHLD);
-       assert(sigprocmask(SIG_BLOCK, &set, NULL) == 0);
+       assert(ha_sigmask(SIG_BLOCK, &set, NULL) == 0);
 }
 
 void unblock_sigchld(void)
@@ -1626,7 +1626,7 @@ void unblock_sigchld(void)
        sigset_t set;
        sigemptyset(&set);
        sigaddset(&set, SIGCHLD);
-       assert(sigprocmask(SIG_UNBLOCK, &set, NULL) == 0);
+       assert(ha_sigmask(SIG_UNBLOCK, &set, NULL) == 0);
 }
 
 static struct pid_list *pid_list_add(pid_t pid, struct task *t)
index 96b8abcf9b26b22fd75192d331359095d491e3c3..1c0455c56a06a2a238b3b92c2efdc585e069cbf2 100644 (file)
@@ -508,7 +508,7 @@ static void mworker_block_signals()
        sigaddset(&set, SIGHUP);
        sigaddset(&set, SIGINT);
        sigaddset(&set, SIGTERM);
-       sigprocmask(SIG_SETMASK, &set, NULL);
+       ha_sigmask(SIG_SETMASK, &set, NULL);
 }
 
 static void mworker_unblock_signals()
@@ -521,7 +521,7 @@ static void mworker_unblock_signals()
        sigaddset(&set, SIGHUP);
        sigaddset(&set, SIGINT);
        sigaddset(&set, SIGTERM);
-       sigprocmask(SIG_UNBLOCK, &set, NULL);
+       ha_sigmask(SIG_UNBLOCK, &set, NULL);
 }
 
 static void mworker_unregister_signals()
index 0dadd762c106e129e3c3b69dea577111e0ad62fe..4bee7d70e3bfbbcf850ed870672ebf12c773b741 100644 (file)
@@ -13,6 +13,8 @@
 #include <signal.h>
 #include <string.h>
 
+#include <common/hathreads.h>
+
 #include <proto/signal.h>
 #include <proto/log.h>
 #include <proto/task.h>
@@ -71,7 +73,7 @@ void __signal_process_queue()
        sigset_t old_sig;
 
        /* block signal delivery during processing */
-       sigprocmask(SIG_SETMASK, &blocked_sig, &old_sig);
+       ha_sigmask(SIG_SETMASK, &blocked_sig, &old_sig);
 
        /* It is important that we scan the queue forwards so that we can
         * catch any signal that would have been queued by another signal
@@ -95,7 +97,7 @@ void __signal_process_queue()
        signal_queue_len = 0;
 
        /* restore signal delivery */
-       sigprocmask(SIG_SETMASK, &old_sig, NULL);
+       ha_sigmask(SIG_SETMASK, &old_sig, NULL);
 }
 
 /* perform minimal intializations, report 0 in case of error, 1 if OK. */
@@ -116,7 +118,7 @@ int signal_init()
         * parsing We don't want the process to be killed by an unregistered
         * USR2 signal when the master-worker is reloading */
        sigaddset(&blocked_sig, SIGUSR2);
-       sigprocmask(SIG_SETMASK, &blocked_sig, NULL);
+       ha_sigmask(SIG_SETMASK, &blocked_sig, NULL);
 
        sigfillset(&blocked_sig);
        sigdelset(&blocked_sig, SIGPROF);