From 6ba7f1d2e6364c491fd4d28cd0dde5a7fea43824 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 12 Mar 2004 01:09:38 +0000 Subject: [PATCH] reduce SignalHandler dependency on StepMania.cpp --- .../src/arch/ArchHooks/ArchHooks_Unix.cpp | 48 +++++++++++++++++++ stepmania/src/archutils/Unix/CrashHandler.cpp | 6 --- .../src/archutils/Unix/SignalHandler.cpp | 11 ----- 3 files changed, 48 insertions(+), 17 deletions(-) diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_Unix.cpp b/stepmania/src/arch/ArchHooks/ArchHooks_Unix.cpp index b8c5f3282a..fed1fa96b4 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_Unix.cpp +++ b/stepmania/src/arch/ArchHooks/ArchHooks_Unix.cpp @@ -12,17 +12,62 @@ #include "SDL_utils.h" +static bool IsFatalSignal( int signal ) +{ + switch( signal ) + { + case SIGINT: + case SIGTERM: + case SIGHUP: + return true; + default: + return false; + } +} + +static void DoCleanShutdown( int signal ) +{ + if( IsFatalSignal(signal) ) + return; + + /* ^C. */ + ExitGame(); +} + +static void DoCrashSignalHandler( int signal ) +{ + /* Don't dump a debug file if the user just hit ^C. */ + if( !IsFatalSignal(signal) ) + return; + + CrashSignalHandler( signal ); +} + static void EmergencyShutdown( int signal ) { + if( !IsFatalSignal(signal) ) + return; + /* If we don't actually use SDL for video, this should be a no-op. Only * do this if the main thread crashes; trying to shut down from * another thread causes crashes (eg. GL may be using TLS). */ if( !strcmp(RageThread::GetCurThreadName(), "Main thread") && SDL_WasInit(SDL_INIT_VIDEO) ) SDL_QuitSubSystem(SDL_INIT_VIDEO); } + +static void KillSelf( int signal ) +{ + if( !IsFatalSignal(signal) ) + return; + + kill( 0, SIGKILL ); +} ArchHooks_Unix::ArchHooks_Unix() { + /* First, handle non-fatal termination signals. */ + SignalHandler::OnClose( DoCleanShutdown ); + #if defined(CRASH_HANDLER) CrashHandlerHandleArgs( g_argc, g_argv ); InitializeCrashHandler(); @@ -32,6 +77,9 @@ ArchHooks_Unix::ArchHooks_Unix() /* Set up EmergencyShutdown, to try to shut down the window if we crash. * This might blow up, so be sure to do it after the crash handler. */ SignalHandler::OnClose( EmergencyShutdown ); + + /* On fatal crashes, after the above, kill ourself so we don't return. */ + SignalHandler::OnClose( KillSelf ); } void ArchHooks_Unix::DumpDebugInfo() diff --git a/stepmania/src/archutils/Unix/CrashHandler.cpp b/stepmania/src/archutils/Unix/CrashHandler.cpp index 1ccbb757f8..db5b498e01 100644 --- a/stepmania/src/archutils/Unix/CrashHandler.cpp +++ b/stepmania/src/archutils/Unix/CrashHandler.cpp @@ -446,12 +446,6 @@ static void do_backtrace( const void **buf, size_t size ) void CrashSignalHandler( int signal ) { -#if !defined(BACKTRACE_METHOD_POWERPC_DARWIN) - /* Don't dump a debug file if the user just hit ^C. */ - if( signal == SIGINT || signal == SIGTERM || signal == SIGHUP ) - return; -#endif - if( g_pCrashHandlerArgv0 ) { safe_print(fileno(stderr), "Crash handler failed: CrashHandlerHandleArgs was not called\n", NULL); diff --git a/stepmania/src/archutils/Unix/SignalHandler.cpp b/stepmania/src/archutils/Unix/SignalHandler.cpp index 918e597d8d..7f7b9abaea 100644 --- a/stepmania/src/archutils/Unix/SignalHandler.cpp +++ b/stepmania/src/archutils/Unix/SignalHandler.cpp @@ -3,7 +3,6 @@ #include "RageLog.h" #include "SignalHandler.h" #include "GetSysInfo.h" -#include "StepMania.h" #include #include @@ -49,18 +48,8 @@ SaveSignals::~SaveSignals() static void SigHandler(int sig) { - if( sig == SIGINT || sig == SIGQUIT ) - { - /* ^C. */ - ExitGame(); - return; - } - for(unsigned i = 0; i < handlers.size(); ++i) handlers[i](sig); - - kill( 0, SIGKILL ); - // _exit(1); } /* Hook up events to fatal signals, so we can clean up if we're killed. */