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"
|
2004-03-28 02:04:23 +00:00
|
|
|
#include "archutils/Unix/LinuxThreadHelpers.h"
|
2004-04-13 08:05:50 +00:00
|
|
|
#include <unistd.h>
|
2004-04-18 23:19:55 +00:00
|
|
|
#include "RageUtil.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 false;
|
2004-03-12 02:58:54 +00:00
|
|
|
default:
|
|
|
|
|
return true;
|
2004-03-12 01:09:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-19 05:01:53 +00:00
|
|
|
static void DoCleanShutdown( int signal, siginfo_t *si, const ucontext_t *uc )
|
2004-03-12 01:09:38 +00:00
|
|
|
{
|
|
|
|
|
if( IsFatalSignal(signal) )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* ^C. */
|
|
|
|
|
ExitGame();
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-19 05:01:53 +00:00
|
|
|
static void DoCrashSignalHandler( int signal, siginfo_t *si, const ucontext_t *uc )
|
2004-03-12 01:09:38 +00:00
|
|
|
{
|
|
|
|
|
/* Don't dump a debug file if the user just hit ^C. */
|
|
|
|
|
if( !IsFatalSignal(signal) )
|
|
|
|
|
return;
|
|
|
|
|
|
2004-03-19 05:01:53 +00:00
|
|
|
CrashSignalHandler( signal, si, uc );
|
2004-03-12 01:09:38 +00:00
|
|
|
}
|
|
|
|
|
|
2004-03-19 05:01:53 +00:00
|
|
|
static void EmergencyShutdown( int signal, siginfo_t *si, const ucontext_t *uc )
|
2003-07-29 21:00:35 +00:00
|
|
|
{
|
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
|
|
|
|
2004-04-09 20:57:58 +00:00
|
|
|
kill( getpid(), SIGKILL );
|
2004-03-12 01:09:38 +00:00
|
|
|
}
|
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();
|
2004-03-12 02:58:54 +00:00
|
|
|
SignalHandler::OnClose( DoCrashSignalHandler );
|
2003-07-24 08:19:20 +00:00
|
|
|
#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 );
|
2003-07-24 08:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
2004-03-28 02:04:23 +00:00
|
|
|
#ifndef _CS_GNU_LIBC_VERSION
|
|
|
|
|
#define _CS_GNU_LIBC_VERSION 2
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static CString LibcVersion()
|
|
|
|
|
{
|
2004-03-29 20:47:29 +00:00
|
|
|
char buf[1024] = "(error)";
|
2004-03-28 02:04:23 +00:00
|
|
|
int ret = confstr( _CS_GNU_LIBC_VERSION, buf, sizeof(buf) );
|
|
|
|
|
if( ret == -1 )
|
|
|
|
|
return "(unknown)";
|
|
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
2004-03-28 02:04:23 +00:00
|
|
|
|
|
|
|
|
LOG->Info( "Runtime library: %s", LibcVersion().c_str() );
|
|
|
|
|
LOG->Info( "Threads library: %s", ThreadsVersion().c_str() );
|
2003-09-16 03:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
2004-04-18 23:13:22 +00:00
|
|
|
void ArchHooks_Unix::SetTime( tm newtime )
|
|
|
|
|
{
|
|
|
|
|
CString sCommand = ssprintf( "%02d%02d%02d%02d%04d.%02d",
|
|
|
|
|
newtime.tm_mon+1,
|
|
|
|
|
newtime.tm_mday,
|
|
|
|
|
newtime.tm_hour,
|
|
|
|
|
newtime.tm_min,
|
|
|
|
|
newtime.tm_year+1900,
|
|
|
|
|
newtime.tm_sec );
|
|
|
|
|
|
|
|
|
|
LOG->Trace( "executing '%s'", sCommand.c_str() );
|
|
|
|
|
system( sCommand );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-24 08:19:20 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2003 by the person(s) listed below. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Glenn Maynard
|
|
|
|
|
*/
|