From b8a43ce275cbc019cc30030897dfa5a271ff823e Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 22 Oct 2007 17:25:41 +0000 Subject: Bite the bullet and use sigaction() instead, since [1803] shows that signal() works badly on SuckOS, and James reports that BSD doesn't have sigset(). --- lib/common/Timer.cpp | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/common/Timer.cpp b/lib/common/Timer.cpp index 9ab45b92..2e146aa3 100644 --- a/lib/common/Timer.cpp +++ b/lib/common/Timer.cpp @@ -39,9 +39,16 @@ void Timers::Init() InitTimer(); SetTimerHandler(Timers::SignalHandler); #else - sighandler_t oldHandler = ::sigset(SIGALRM, - Timers::SignalHandler); - ASSERT(oldHandler == 0); + struct sigaction newact, oldact; + newact.sa_handler = Timers::SignalHandler; + newact.sa_flags = SA_RESTART; + ::sigemptyset(&newact.sa_mask); + if (::sigaction(SIGALRM, &newact, &oldact) != 0) + { + BOX_ERROR("Failed to install signal handler"); + THROW_EXCEPTION(CommonException, Internal); + } + ASSERT(oldact.sa_handler == 0); #endif // WIN32 && !PLATFORM_CYGWIN spTimers = new std::vector; @@ -70,8 +77,16 @@ void Timers::Cleanup() int result = ::setitimer(ITIMER_REAL, &timeout, NULL); ASSERT(result == 0); - sighandler_t oldHandler = ::sigset(SIGALRM, NULL); - ASSERT(oldHandler == Timers::SignalHandler); + struct sigaction newact, oldact; + newact.sa_handler = SIG_DFL; + newact.sa_flags = SA_RESTART; + ::sigemptyset(&newact.sa_mask); + if (::sigaction(SIGALRM, &newact, &oldact) != 0) + { + BOX_ERROR("Failed to remove signal handler"); + THROW_EXCEPTION(CommonException, Internal); + } + ASSERT(oldact.sa_handler == Timers::SignalHandler); #endif // WIN32 && !PLATFORM_CYGWIN spTimers->clear(); @@ -154,13 +169,21 @@ void Timers::Reschedule() } #ifndef WIN32 - void (*oldhandler)(int) = ::sigset(SIGALRM, Timers::SignalHandler); - if (oldhandler != Timers::SignalHandler) - { - printf("Signal handler was %p, expected %p\n", - oldhandler, Timers::SignalHandler); - THROW_EXCEPTION(CommonException, Internal) - } + struct sigaction oldact; + if (::sigaction(SIGALRM, NULL, &oldact) != 0) + { + BOX_ERROR("Failed to check signal handler"); + THROW_EXCEPTION(CommonException, Internal) + } + + ASSERT(oldact.sa_handler == Timers::SignalHandler); + + if (oldact.sa_handler != Timers::SignalHandler) + { + printf("Signal handler was %p, expected %p\n", + oldact.sa_handler, Timers::SignalHandler); + THROW_EXCEPTION(CommonException, Internal) + } #endif // Clear the reschedule-needed flag to false before we start. -- cgit v1.2.3