From f116061b9ff6860c25f2eff5763d64402296234b Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 19 Apr 2004 23:40:34 +0000 Subject: [PATCH] handle signals like in *nix; handles stack overflow and thread crashes better --- .../src/arch/ArchHooks/ArchHooks_darwin.cpp | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp b/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp index 4427213be8..0b087419e8 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp +++ b/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp @@ -50,11 +50,32 @@ SInt16 ShowAlert(int type, CFStringRef message, CFStringRef OK, CFStringRef canc return result; } -/* The signal handler is only used to trap SIGABRT; for other signals, just return - * and the exceptoin handler will take care of it. */ +static bool IsFatalSignal( int signal ) +{ + switch( signal ) + { + case SIGINT: + case SIGTERM: + case SIGHUP: + return false; + default: + return true; + } +} + +static void DoCleanShutdown( int signal, siginfo_t *si, const ucontext_t *uc ) +{ + if( IsFatalSignal(signal) ) + return; + + /* ^C. */ + ExitGame(); +} + static void DoCrashSignalHandler( int signal, siginfo_t *si, const ucontext_t *uc ) { - if( signal != SIGABRT ) + /* Don't dump a debug file if the user just hit ^C. */ + if( !IsFatalSignal(signal) ) return; CrashSignalHandler( signal, si, uc ); @@ -64,7 +85,10 @@ static void DoCrashSignalHandler( int signal, siginfo_t *si, const ucontext_t *u ArchHooks_darwin::ArchHooks_darwin() { CrashHandlerHandleArgs(g_argc, g_argv); - InstallExceptionHandler(CrashExceptionHandler); + + /* First, handle non-fatal termination signals. */ + SignalHandler::OnClose( DoCleanShutdown ); + SignalHandler::OnClose( DoCrashSignalHandler ); TimeCritMutex = new RageMutex("TimeCritMutex"); }