summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/anytun.cpp2
-rw-r--r--src/posix/signalHandler.hpp30
2 files changed, 20 insertions, 12 deletions
diff --git a/src/anytun.cpp b/src/anytun.cpp
index 48ef739..e9f2452 100644
--- a/src/anytun.cpp
+++ b/src/anytun.cpp
@@ -422,10 +422,8 @@ int main(int argc, char* argv[])
privs.drop();
#endif
#endif
-#if !defined(__FreeBSD_kernel__)
// this has to be called before the first thread is started
gSignalController.init(service);
-#endif
gResolver.init();
#ifndef NO_EXEC
boost::thread(boost::bind(&TunDevice::waitUntilReady,&dev));
diff --git a/src/posix/signalHandler.hpp b/src/posix/signalHandler.hpp
index 8b3494e..35075b9 100644
--- a/src/posix/signalHandler.hpp
+++ b/src/posix/signalHandler.hpp
@@ -75,14 +75,22 @@ int SigUsr2Handler(int /*sig*/, const std::string& /*msg*/)
void handleSignal()
{
+ struct timespec timeout;
sigset_t signal_set;
int sigNum;
- int err = 0;
while(1) {
- sigfillset(&signal_set);
- err = sigwait(&signal_set, &sigNum);
- if (err) {
- if (err != EINTR && errno != EINTR ) {
+ sigemptyset(&signal_set);
+ sigaddset(&signal_set, SIGINT);
+ sigaddset(&signal_set, SIGQUIT);
+ sigaddset(&signal_set, SIGHUP);
+ sigaddset(&signal_set, SIGTERM);
+ sigaddset(&signal_set, SIGUSR1);
+ sigaddset(&signal_set, SIGUSR2);
+ timeout.tv_sec = 1;
+ timeout.tv_nsec = 0;
+ sigNum = sigtimedwait(&signal_set, NULL, &timeout);
+ if (sigNum == -1) {
+ if (errno != EINTR && errno != EAGAIN) {
cLog.msg(Log::PRIO_ERROR) << "sigwait failed with error: \"" << AnytunErrno(errno) << "\" SignalHandling will be disabled";
break;
}
@@ -96,11 +104,13 @@ void registerSignalHandler(SignalController& ctrl, DaemonService* /*service*/)
{
sigset_t signal_set;
- sigfillset(&signal_set);
- sigdelset(&signal_set, SIGCHLD);
- sigdelset(&signal_set, SIGSEGV);
- sigdelset(&signal_set, SIGBUS);
- sigdelset(&signal_set, SIGFPE);
+ sigemptyset(&signal_set);
+ sigaddset(&signal_set, SIGINT);
+ sigaddset(&signal_set, SIGQUIT);
+ sigaddset(&signal_set, SIGHUP);
+ sigaddset(&signal_set, SIGTERM);
+ sigaddset(&signal_set, SIGUSR1);
+ sigaddset(&signal_set, SIGUSR2);
#if defined(BOOST_HAS_PTHREADS)
pthread_sigmask(SIG_BLOCK, &signal_set, NULL);