reduce SignalHandler dependency on StepMania.cpp
This commit is contained in:
@@ -12,8 +12,42 @@
|
|||||||
|
|
||||||
#include "SDL_utils.h"
|
#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 )
|
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
|
/* 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
|
* do this if the main thread crashes; trying to shut down from
|
||||||
* another thread causes crashes (eg. GL may be using TLS). */
|
* another thread causes crashes (eg. GL may be using TLS). */
|
||||||
@@ -21,8 +55,19 @@ static void EmergencyShutdown( int signal )
|
|||||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void KillSelf( int signal )
|
||||||
|
{
|
||||||
|
if( !IsFatalSignal(signal) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
kill( 0, SIGKILL );
|
||||||
|
}
|
||||||
|
|
||||||
ArchHooks_Unix::ArchHooks_Unix()
|
ArchHooks_Unix::ArchHooks_Unix()
|
||||||
{
|
{
|
||||||
|
/* First, handle non-fatal termination signals. */
|
||||||
|
SignalHandler::OnClose( DoCleanShutdown );
|
||||||
|
|
||||||
#if defined(CRASH_HANDLER)
|
#if defined(CRASH_HANDLER)
|
||||||
CrashHandlerHandleArgs( g_argc, g_argv );
|
CrashHandlerHandleArgs( g_argc, g_argv );
|
||||||
InitializeCrashHandler();
|
InitializeCrashHandler();
|
||||||
@@ -32,6 +77,9 @@ ArchHooks_Unix::ArchHooks_Unix()
|
|||||||
/* Set up EmergencyShutdown, to try to shut down the window if we crash.
|
/* 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. */
|
* This might blow up, so be sure to do it after the crash handler. */
|
||||||
SignalHandler::OnClose( EmergencyShutdown );
|
SignalHandler::OnClose( EmergencyShutdown );
|
||||||
|
|
||||||
|
/* On fatal crashes, after the above, kill ourself so we don't return. */
|
||||||
|
SignalHandler::OnClose( KillSelf );
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchHooks_Unix::DumpDebugInfo()
|
void ArchHooks_Unix::DumpDebugInfo()
|
||||||
|
|||||||
@@ -446,12 +446,6 @@ static void do_backtrace( const void **buf, size_t size )
|
|||||||
|
|
||||||
void CrashSignalHandler( int signal )
|
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 )
|
if( g_pCrashHandlerArgv0 )
|
||||||
{
|
{
|
||||||
safe_print(fileno(stderr), "Crash handler failed: CrashHandlerHandleArgs was not called\n", NULL);
|
safe_print(fileno(stderr), "Crash handler failed: CrashHandlerHandleArgs was not called\n", NULL);
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#include "RageLog.h"
|
#include "RageLog.h"
|
||||||
#include "SignalHandler.h"
|
#include "SignalHandler.h"
|
||||||
#include "GetSysInfo.h"
|
#include "GetSysInfo.h"
|
||||||
#include "StepMania.h"
|
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
@@ -49,18 +48,8 @@ SaveSignals::~SaveSignals()
|
|||||||
|
|
||||||
static void SigHandler(int sig)
|
static void SigHandler(int sig)
|
||||||
{
|
{
|
||||||
if( sig == SIGINT || sig == SIGQUIT )
|
|
||||||
{
|
|
||||||
/* ^C. */
|
|
||||||
ExitGame();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(unsigned i = 0; i < handlers.size(); ++i)
|
for(unsigned i = 0; i < handlers.size(); ++i)
|
||||||
handlers[i](sig);
|
handlers[i](sig);
|
||||||
|
|
||||||
kill( 0, SIGKILL );
|
|
||||||
// _exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Hook up events to fatal signals, so we can clean up if we're killed. */
|
/* Hook up events to fatal signals, so we can clean up if we're killed. */
|
||||||
|
|||||||
Reference in New Issue
Block a user