]> git.saurik.com Git - redis.git/commitdiff
Mask SIGALRM everything but in the main thread.
authorantirez <antirez@gmail.com>
Tue, 27 Mar 2012 11:48:53 +0000 (13:48 +0200)
committerantirez <antirez@gmail.com>
Wed, 28 Mar 2012 11:18:21 +0000 (13:18 +0200)
This is required to ensure that the signal will be delivered to the main
thread when the watchdog timer expires.

src/bio.c

index eaac8e40d55663caf3fbacf4212a01247ba26972..aa2cdf9fbb5a0d9289eefa825c2aa62048b66f64 100644 (file)
--- a/src/bio.c
+++ b/src/bio.c
@@ -108,9 +108,18 @@ void bioCreateBackgroundJob(int type, void *arg1, void *arg2, void *arg3) {
 void *bioProcessBackgroundJobs(void *arg) {
     struct bio_job *job;
     unsigned long type = (unsigned long) arg;
+    sigset_t sigset;
 
     pthread_detach(pthread_self());
     pthread_mutex_lock(&bio_mutex[type]);
+    /* Block SIGALRM so we are sure that only the main thread will
+     * receive the watchdog signal. */
+    sigemptyset(&sigset);
+    sigaddset(&sigset, SIGALRM);
+    if (pthread_sigmask(SIG_BLOCK, &sigset, NULL))
+        redisLog(REDIS_WARNING,
+            "Warning: can't mask SIGALRM in bio.c thread: %s", strerror(errno));
+
     while(1) {
         listNode *ln;