+
+ // Block SIGHUP; only the main thread should see that.
+ // (This isn't strictly required, but it makes it easier to debug that indeed
+ // SIGUSR1 was what woke us up.)
+ sigset_t set;
+ sigemptyset(&set);
+ sigaddset(&set, SIGHUP);
+ int err = pthread_sigmask(SIG_BLOCK, &set, nullptr);
+ if (err != 0) {
+ errno = err;
+ log_perror("pthread_sigmask");
+ exit(1);
+ }
+
+ // Block SIGUSR1, and store the old signal mask.
+ sigemptyset(&set);
+ sigaddset(&set, SIGUSR1);
+ err = pthread_sigmask(SIG_BLOCK, &set, &thread->sigset_without_usr1_block);
+ if (err != 0) {
+ errno = err;
+ log_perror("pthread_sigmask");
+ exit(1);
+ }
+
+ // Call the right thunk.