2003-07-24 08:19:20 +00:00
|
|
|
#include "global.h"
|
2003-09-16 03:20:18 +00:00
|
|
|
#include "RageLog.h"
|
2004-02-06 04:46:47 +00:00
|
|
|
#include "RageThreads.h"
|
2003-07-24 08:19:20 +00:00
|
|
|
#include "ArchHooks_Unix.h"
|
2004-03-11 23:58:49 +00:00
|
|
|
#include "StepMania.h"
|
2003-07-24 08:19:20 +00:00
|
|
|
#include "archutils/Unix/SignalHandler.h"
|
2003-11-28 21:34:05 +00:00
|
|
|
#include "archutils/Unix/GetSysInfo.h"
|
2003-07-24 08:19:20 +00:00
|
|
|
|
2003-07-29 21:00:35 +00:00
|
|
|
#if defined(CRASH_HANDLER)
|
2003-07-24 08:19:20 +00:00
|
|
|
#include "archutils/Unix/CrashHandler.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-07-29 21:00:35 +00:00
|
|
|
#include "SDL_utils.h"
|
|
|
|
|
|
2004-03-12 01:09:38 +00:00
|
|
|
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 );
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-29 21:00:35 +00:00
|
|
|
static void EmergencyShutdown( int signal )
|
|
|
|
|
{
|
2004-03-12 01:09:38 +00:00
|
|
|
if( !IsFatalSignal(signal) )
|
|
|
|
|
return;
|
|
|
|
|
|
2004-02-06 04:46:47 +00:00
|
|
|
/* 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) )
|
2003-07-29 21:00:35 +00:00
|
|
|
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
|
|
|
|
}
|
2004-03-12 01:09:38 +00:00
|
|
|
|
|
|
|
|
static void KillSelf( int signal )
|
|
|
|
|
{
|
|
|
|
|
if( !IsFatalSignal(signal) )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
kill( 0, SIGKILL );
|
|
|
|
|
}
|
2003-07-29 21:00:35 +00:00
|
|
|
|
2003-07-24 08:19:20 +00:00
|
|
|
ArchHooks_Unix::ArchHooks_Unix()
|
|
|
|
|
{
|
2004-03-12 01:09:38 +00:00
|
|
|
/* First, handle non-fatal termination signals. */
|
|
|
|
|
SignalHandler::OnClose( DoCleanShutdown );
|
|
|
|
|
|
2003-07-29 21:00:35 +00:00
|
|
|
#if defined(CRASH_HANDLER)
|
2004-03-11 23:58:49 +00:00
|
|
|
CrashHandlerHandleArgs( g_argc, g_argv );
|
2003-11-11 23:36:31 +00:00
|
|
|
InitializeCrashHandler();
|
2003-07-24 08:19:20 +00:00
|
|
|
SignalHandler::OnClose( CrashSignalHandler );
|
|
|
|
|
#endif
|
2003-07-29 21:00:35 +00:00
|
|
|
|
|
|
|
|
/* 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 );
|
2004-03-12 01:09:38 +00:00
|
|
|
|
|
|
|
|
/* On fatal crashes, after the above, kill ourself so we don't return. */
|
|
|
|
|
SignalHandler::OnClose( KillSelf );
|
2003-07-24 08:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
2003-09-16 03:20:18 +00:00
|
|
|
void ArchHooks_Unix::DumpDebugInfo()
|
|
|
|
|
{
|
2003-11-28 21:34:05 +00:00
|
|
|
CString sys;
|
|
|
|
|
int vers;
|
|
|
|
|
GetKernel( sys, vers );
|
2004-01-02 07:01:27 +00:00
|
|
|
LOG->Info( "OS: %s ver %06i", sys.c_str(), vers );
|
2003-11-28 21:34:05 +00:00
|
|
|
|
2003-09-16 03:20:18 +00:00
|
|
|
#if defined(CRASH_HANDLER)
|
|
|
|
|
LOG->Info( "Crash backtrace component: %s", BACKTRACE_METHOD_TEXT );
|
|
|
|
|
LOG->Info( "Crash lookup component: %s", BACKTRACE_LOOKUP_METHOD_TEXT );
|
2003-12-22 02:16:33 +00:00
|
|
|
#if defined(BACKTRACE_DEMANGLE_METHOD_TEXT)
|
2003-12-22 02:16:04 +00:00
|
|
|
LOG->Info( "Crash demangle component: %s", BACKTRACE_DEMANGLE_METHOD_TEXT );
|
2003-09-16 03:20:18 +00:00
|
|
|
#endif
|
2003-12-22 02:16:33 +00:00
|
|
|
#endif
|
2003-09-16 03:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
2003-07-24 08:19:20 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2003 by the person(s) listed below. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Glenn Maynard
|
|
|
|
|
*/
|