summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2015-05-27 23:44:23 +0200
committerFlorent Le Coz <louiz@louiz.org>2015-05-27 23:44:23 +0200
commit897b281e67dc82700db9fd9c2dedc5e01e5871ee (patch)
treec6b2d8eebdb5ce2c7ae10a475827fd95c08cd9b7 /src
parent54f96debcaa80ea2d49f722b0df11d227943ebba (diff)
downloadbiboumi-897b281e67dc82700db9fd9c2dedc5e01e5871ee.tar.gz
biboumi-897b281e67dc82700db9fd9c2dedc5e01e5871ee.tar.bz2
biboumi-897b281e67dc82700db9fd9c2dedc5e01e5871ee.tar.xz
biboumi-897b281e67dc82700db9fd9c2dedc5e01e5871ee.zip
Avoid some potential race conditions by blocking the signals we manage
They are atomically unblocked in the ppoll/epoll_pwait calls, avoiding any race condition on the check of the “stop” or “reload” booleans.
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 4a207b9..adc0c7c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -99,9 +99,19 @@ int main(int ac, char** av)
if (hostname.empty())
return config_help("hostname");
+ // Block the signals we want to manage. They will be unblocked only during
+ // the epoll_pwait or ppoll calls. This avoids some race conditions,
+ // explained in man 2 pselect on linux
+ sigset_t mask;
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGINT);
+ sigaddset(&mask, SIGTERM);
+ sigaddset(&mask, SIGUSR1);
+ sigaddset(&mask, SIGUSR2);
+ sigprocmask(SIG_BLOCK, &mask, nullptr);
+
// Install the signals used to exit the process cleanly, or reload the
// config
- sigset_t mask;
sigemptyset(&mask);
struct sigaction on_sigint;
on_sigint.sa_sigaction = &sigint_handler;