reduce crash handler dependency on StepMania.cpp
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "RageLog.h"
|
||||
#include "RageThreads.h"
|
||||
#include "ArchHooks_Unix.h"
|
||||
#include "StepMania.h"
|
||||
#include "archutils/Unix/SignalHandler.h"
|
||||
#include "archutils/Unix/GetSysInfo.h"
|
||||
|
||||
@@ -23,7 +24,7 @@ static void EmergencyShutdown( int signal )
|
||||
ArchHooks_Unix::ArchHooks_Unix()
|
||||
{
|
||||
#if defined(CRASH_HANDLER)
|
||||
CrashHandlerHandleArgs();
|
||||
CrashHandlerHandleArgs( g_argc, g_argv );
|
||||
InitializeCrashHandler();
|
||||
SignalHandler::OnClose( CrashSignalHandler );
|
||||
#endif
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "RageLog.h"
|
||||
#include "archutils/Darwin/Crash.h"
|
||||
#include "archutils/Unix/CrashHandler.h"
|
||||
#include "StepMania.h"
|
||||
#include <Carbon/Carbon.h>
|
||||
#include <signal.h>
|
||||
|
||||
@@ -40,7 +41,7 @@ SInt16 ShowAlert(int type, CFStringRef message, CFStringRef OK, CFStringRef canc
|
||||
|
||||
ArchHooks_darwin::ArchHooks_darwin()
|
||||
{
|
||||
CrashHandlerHandleArgs();
|
||||
CrashHandlerHandleArgs( g_argc, g_argv );
|
||||
|
||||
long response;
|
||||
CString error = "";
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
#include <limits.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "StepMania.h" /* for g_argv */
|
||||
|
||||
#include "RageLog.h" /* for RageLog::GetAdditionalLog, etc, only */
|
||||
#include "RageThreads.h"
|
||||
|
||||
@@ -20,6 +18,8 @@
|
||||
#include "CrashHandler.h"
|
||||
#include "CrashHandlerInternal.h"
|
||||
|
||||
extern const char *g_pCrashHandlerArgv0;
|
||||
|
||||
static void safe_print(int fd, ...)
|
||||
{
|
||||
va_list ap;
|
||||
@@ -49,10 +49,10 @@ static void NORETURN spawn_child_process( int from_parent )
|
||||
close(from_parent);
|
||||
}
|
||||
|
||||
execl(g_argv[0], g_argv[0], CHILD_MAGIC_PARAMETER, NULL);
|
||||
execl( g_pCrashHandlerArgv0, g_pCrashHandlerArgv0, CHILD_MAGIC_PARAMETER, NULL);
|
||||
|
||||
/* If we got here, the exec failed. */
|
||||
safe_print(fileno(stderr), "Crash handler execl(", g_argv[0], ") failed: ", strerror(errno), "\n", NULL);
|
||||
safe_print(fileno(stderr), "Crash handler execl(", g_pCrashHandlerArgv0, ") failed: ", strerror(errno), "\n", NULL);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
@@ -452,9 +452,9 @@ void CrashSignalHandler( int signal )
|
||||
return;
|
||||
#endif
|
||||
|
||||
if( g_argv == 0 || g_argc < 1 )
|
||||
if( g_pCrashHandlerArgv0 )
|
||||
{
|
||||
safe_print(fileno(stderr), "Crash handler failed: g_argv or g_argc not set\n", NULL);
|
||||
safe_print(fileno(stderr), "Crash handler failed: CrashHandlerHandleArgs was not called\n", NULL);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define CRASH_HANDLER_H
|
||||
|
||||
void CrashSignalHandler(int signal);
|
||||
void CrashHandlerHandleArgs();
|
||||
void CrashHandlerHandleArgs( int argc, char* argv[] );
|
||||
void InitializeCrashHandler();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include "StepMania.h" /* for g_argv */
|
||||
#include "RageUtil.h"
|
||||
#include "CrashHandler.h"
|
||||
#include "CrashHandlerInternal.h"
|
||||
@@ -27,6 +26,8 @@
|
||||
extern const unsigned version_num;
|
||||
#endif
|
||||
|
||||
const char *g_pCrashHandlerArgv0 = NULL;
|
||||
|
||||
struct BacktraceNames
|
||||
{
|
||||
CString Symbol, File;
|
||||
@@ -100,7 +101,7 @@ CString BacktraceNames::Format() const
|
||||
if( ShortenedPath != "" )
|
||||
{
|
||||
/* We have some sort of symbol name, so abbreviate or elide the module name. */
|
||||
if( ShortenedPath == g_argv[0] )
|
||||
if( ShortenedPath == g_pCrashHandlerArgv0 )
|
||||
ShortenedPath = "";
|
||||
else
|
||||
{
|
||||
@@ -507,13 +508,14 @@ static void child_process()
|
||||
}
|
||||
|
||||
|
||||
void CrashHandlerHandleArgs()
|
||||
void CrashHandlerHandleArgs( int argc, char* argv[] )
|
||||
{
|
||||
if(g_argc == 2 && !strcmp(g_argv[1], CHILD_MAGIC_PARAMETER))
|
||||
{
|
||||
child_process();
|
||||
exit(0);
|
||||
}
|
||||
g_pCrashHandlerArgv0 = argv[0];
|
||||
if( argc == 2 && !strcmp(argv[1], CHILD_MAGIC_PARAMETER) )
|
||||
{
|
||||
child_process();
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user