[Box Backup-commit] COMMIT r1947 - box/chris/general/lib/common

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Sat Dec 8 21:41:38 GMT 2007


Author: chris
Date: 2007-12-08 21:41:38 +0000 (Sat, 08 Dec 2007)
New Revision: 1947

Modified:
   box/chris/general/lib/common/Timer.cpp
Log:
Bite the bullet and use sigaction() instead, since [1803] shows that
signal() works badly on Solaris, and James reports that BSD doesn't
have sigset(). (merges [1900] and [1902])


Modified: box/chris/general/lib/common/Timer.cpp
===================================================================
--- box/chris/general/lib/common/Timer.cpp	2007-12-08 21:30:20 UTC (rev 1946)
+++ box/chris/general/lib/common/Timer.cpp	2007-12-08 21:41:38 UTC (rev 1947)
@@ -39,9 +39,16 @@
 		InitTimer();
 		SetTimerHandler(Timers::SignalHandler);
 	#else
-		sighandler_t oldHandler = ::signal(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 @@
 		int result = ::setitimer(ITIMER_REAL, &timeout, NULL);
 		ASSERT(result == 0);
 
-		sighandler_t oldHandler = ::signal(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,10 +169,21 @@
 	}
 
 	#ifndef WIN32
-	if (::signal(SIGALRM, Timers::SignalHandler) != 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.




More information about the Boxbackup-commit mailing list