summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2007-10-22 17:25:41 +0000
committerChris Wilson <chris+github@qwirx.com>2007-10-22 17:25:41 +0000
commitb8a43ce275cbc019cc30030897dfa5a271ff823e (patch)
tree06629ffb6be5e8faf48ad425355209467f1b1874
parent36017b41816a8ffedb22a26f956f73d517440d8c (diff)
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().
-rw-r--r--lib/common/Timer.cpp47
1 files changed, 35 insertions, 12 deletions
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<Timer*>;
@@ -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.