From f710fc94e998d013f72af2c35f11776fc89f60b7 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 23 Jan 2010 21:50:48 +0000 Subject: now using sigtimedwait instead of sigwait --- src/anytun.cpp | 2 -- src/posix/signalHandler.hpp | 30 ++++++++++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) (limited to 'src') 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); -- cgit v1.2.3