engine: properly pass shutdown reason down to close log, helps to finally get rid of global finalmsg
This commit is contained in:
parent
98ff33d9e2
commit
0d55441830
6 changed files with 35 additions and 44 deletions
|
@ -301,7 +301,6 @@ typedef struct host_parm_s
|
||||||
poolhandle_t mempool; // static mempool for misc allocations
|
poolhandle_t mempool; // static mempool for misc allocations
|
||||||
poolhandle_t imagepool; // imagelib mempool
|
poolhandle_t imagepool; // imagelib mempool
|
||||||
poolhandle_t soundpool; // soundlib mempool
|
poolhandle_t soundpool; // soundlib mempool
|
||||||
string finalmsg; // server shutdown final message
|
|
||||||
string downloadfile; // filename to be downloading
|
string downloadfile; // filename to be downloading
|
||||||
int downloadcount; // how many files remain to downloading
|
int downloadcount; // how many files remain to downloading
|
||||||
char deferred_cmd[128];// deferred commands
|
char deferred_cmd[128];// deferred commands
|
||||||
|
|
|
@ -362,9 +362,8 @@ static void Host_NewInstance( const char *name, const char *finalmsg )
|
||||||
if( !pChangeGame ) return;
|
if( !pChangeGame ) return;
|
||||||
|
|
||||||
host.change_game = true;
|
host.change_game = true;
|
||||||
Q_strncpy( host.finalmsg, finalmsg, sizeof( host.finalmsg ));
|
|
||||||
|
|
||||||
if( !Sys_NewInstance( name ))
|
if( !Sys_NewInstance( name, finalmsg ))
|
||||||
pChangeGame( name ); // call from hl.exe
|
pChangeGame( name ); // call from hl.exe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -838,7 +837,6 @@ void GAME_EXPORT Host_Error( const char *error, ... )
|
||||||
recursive = true;
|
recursive = true;
|
||||||
Q_strncpy( hosterror2, hosterror1, sizeof( hosterror2 ));
|
Q_strncpy( hosterror2, hosterror1, sizeof( hosterror2 ));
|
||||||
host.errorframe = host.framecount; // to avoid multply calls per frame
|
host.errorframe = host.framecount; // to avoid multply calls per frame
|
||||||
Q_snprintf( host.finalmsg, sizeof( host.finalmsg ), "Server crashed: %s", hosterror1 );
|
|
||||||
|
|
||||||
// clearing cmd buffer to prevent execute any commands
|
// clearing cmd buffer to prevent execute any commands
|
||||||
COM_InitHostState();
|
COM_InitHostState();
|
||||||
|
@ -1359,9 +1357,6 @@ void Host_ShutdownWithReason( const char *reason )
|
||||||
if( host.status != HOST_ERR_FATAL )
|
if( host.status != HOST_ERR_FATAL )
|
||||||
host.status = HOST_SHUTDOWN; // prepare host to normal shutdown
|
host.status = HOST_SHUTDOWN; // prepare host to normal shutdown
|
||||||
|
|
||||||
if( !host.change_game )
|
|
||||||
Q_strncpy( host.finalmsg, "Server shutdown", sizeof( host.finalmsg ));
|
|
||||||
|
|
||||||
#if !XASH_DEDICATED
|
#if !XASH_DEDICATED
|
||||||
if( host.type == HOST_NORMAL && !error )
|
if( host.type == HOST_NORMAL && !error )
|
||||||
Host_WriteConfig();
|
Host_WriteConfig();
|
||||||
|
@ -1384,5 +1379,5 @@ void Host_ShutdownWithReason( const char *reason )
|
||||||
|
|
||||||
// restore filter
|
// restore filter
|
||||||
Sys_RestoreCrashHandler();
|
Sys_RestoreCrashHandler();
|
||||||
Sys_CloseLog();
|
Sys_CloseLog( reason );
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,37 +116,37 @@ void Sys_InitLog( void )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sys_CloseLog( void )
|
void Sys_CloseLog( const char *finalmsg )
|
||||||
{
|
{
|
||||||
char event_name[64];
|
Sys_FlushStdout(); // flush to stdout to ensure all data was written
|
||||||
|
|
||||||
|
if( !s_ld.logfile )
|
||||||
|
return;
|
||||||
|
|
||||||
// continue logged
|
// continue logged
|
||||||
|
if( !finalmsg )
|
||||||
|
{
|
||||||
switch( host.status )
|
switch( host.status )
|
||||||
{
|
{
|
||||||
case HOST_CRASHED:
|
case HOST_CRASHED:
|
||||||
Q_strncpy( event_name, "crashed", sizeof( event_name ));
|
finalmsg = "crashed";
|
||||||
break;
|
break;
|
||||||
case HOST_ERR_FATAL:
|
case HOST_ERR_FATAL:
|
||||||
Q_strncpy( event_name, "stopped with error", sizeof( event_name ));
|
finalmsg = "stopped with error";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if( !host.change_game ) Q_strncpy( event_name, "stopped", sizeof( event_name ));
|
finalmsg = "stopped";
|
||||||
else Q_strncpy( event_name, host.finalmsg, sizeof( event_name ));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Sys_FlushStdout(); // flush to stdout to ensure all data was written
|
|
||||||
|
|
||||||
if( s_ld.logfile )
|
|
||||||
{
|
|
||||||
fputc( '\n', s_ld.logfile );
|
fputc( '\n', s_ld.logfile );
|
||||||
fputs( "================================================================================\n", s_ld.logfile );
|
fputs( "================================================================================\n", s_ld.logfile );
|
||||||
fprintf( s_ld.logfile, "%s (%i, %s, %s, %s-%s)\n", s_ld.title, Q_buildnum(), Q_buildcommit(), Q_buildbranch(), Q_buildos(), Q_buildarch());
|
fprintf( s_ld.logfile, "%s (%i, %s, %s, %s-%s)\n", s_ld.title, Q_buildnum(), Q_buildcommit(), Q_buildbranch(), Q_buildos(), Q_buildarch());
|
||||||
fprintf( s_ld.logfile, "Stopped with reason \"%s\" at %s\n", event_name, Q_timestamp( TIME_FULL ));
|
fprintf( s_ld.logfile, "Stopped with reason \"%s\" at %s\n", finalmsg, Q_timestamp( TIME_FULL ));
|
||||||
fputs( "================================================================================\n", s_ld.logfile );
|
fputs( "================================================================================\n", s_ld.logfile );
|
||||||
fclose( s_ld.logfile );
|
fclose( s_ld.logfile );
|
||||||
s_ld.logfile = NULL;
|
s_ld.logfile = NULL;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if XASH_COLORIZE_CONSOLE
|
#if XASH_COLORIZE_CONSOLE
|
||||||
|
|
|
@ -529,7 +529,7 @@ but since engine will be unloaded during this call
|
||||||
it explicitly doesn't use internal allocation or string copy utils
|
it explicitly doesn't use internal allocation or string copy utils
|
||||||
==================
|
==================
|
||||||
*/
|
*/
|
||||||
qboolean Sys_NewInstance( const char *gamedir )
|
qboolean Sys_NewInstance( const char *gamedir, const char *finalmsg )
|
||||||
{
|
{
|
||||||
#if XASH_NSWITCH
|
#if XASH_NSWITCH
|
||||||
char newargs[4096];
|
char newargs[4096];
|
||||||
|
@ -540,7 +540,7 @@ qboolean Sys_NewInstance( const char *gamedir )
|
||||||
// just restart the entire thing
|
// just restart the entire thing
|
||||||
printf( "envSetNextLoad exe: `%s`\n", exe );
|
printf( "envSetNextLoad exe: `%s`\n", exe );
|
||||||
printf( "envSetNextLoad argv:\n`%s`\n", newargs );
|
printf( "envSetNextLoad argv:\n`%s`\n", newargs );
|
||||||
Host_ShutdownWithReason( "changing game" );
|
Host_ShutdownWithReason( finalmsg );
|
||||||
envSetNextLoad( exe, newargs );
|
envSetNextLoad( exe, newargs );
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
#else
|
#else
|
||||||
|
@ -578,7 +578,7 @@ qboolean Sys_NewInstance( const char *gamedir )
|
||||||
#if XASH_PSVITA
|
#if XASH_PSVITA
|
||||||
// under normal circumstances it's always going to be the same path
|
// under normal circumstances it's always going to be the same path
|
||||||
exe = strdup( "app0:/eboot.bin" );
|
exe = strdup( "app0:/eboot.bin" );
|
||||||
Host_ShutdownWithReason( "changing game" );
|
Host_ShutdownWithReason( finalmsg );
|
||||||
sceAppMgrLoadExec( exe, newargs, NULL );
|
sceAppMgrLoadExec( exe, newargs, NULL );
|
||||||
#else
|
#else
|
||||||
exelen = wai_getExecutablePath( NULL, 0, NULL );
|
exelen = wai_getExecutablePath( NULL, 0, NULL );
|
||||||
|
@ -586,7 +586,7 @@ qboolean Sys_NewInstance( const char *gamedir )
|
||||||
wai_getExecutablePath( exe, exelen, NULL );
|
wai_getExecutablePath( exe, exelen, NULL );
|
||||||
exe[exelen] = 0;
|
exe[exelen] = 0;
|
||||||
|
|
||||||
Host_ShutdownWithReason( "changing game" );
|
Host_ShutdownWithReason( finalmsg );
|
||||||
|
|
||||||
execv( exe, newargs );
|
execv( exe, newargs );
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -56,11 +56,8 @@ void Sys_DebugBreak( void );
|
||||||
qboolean _Sys_GetParmFromCmdLine( const char *parm, char *out, size_t size );
|
qboolean _Sys_GetParmFromCmdLine( const char *parm, char *out, size_t size );
|
||||||
qboolean Sys_GetIntFromCmdLine( const char *parm, int *out );
|
qboolean Sys_GetIntFromCmdLine( const char *parm, int *out );
|
||||||
void Sys_Print( const char *pMsg );
|
void Sys_Print( const char *pMsg );
|
||||||
void Sys_PrintLog( const char *pMsg );
|
|
||||||
void Sys_InitLog( void );
|
|
||||||
void Sys_CloseLog( void );
|
|
||||||
void Sys_Quit( const char *reason ) NORETURN;
|
void Sys_Quit( const char *reason ) NORETURN;
|
||||||
qboolean Sys_NewInstance( const char *gamedir );
|
qboolean Sys_NewInstance( const char *gamedir, const char *finalmsg );
|
||||||
void *Sys_GetNativeObject( const char *obj );
|
void *Sys_GetNativeObject( const char *obj );
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -68,7 +65,7 @@ void *Sys_GetNativeObject( const char *obj );
|
||||||
//
|
//
|
||||||
char *Sys_Input( void );
|
char *Sys_Input( void );
|
||||||
void Sys_DestroyConsole( void );
|
void Sys_DestroyConsole( void );
|
||||||
void Sys_CloseLog( void );
|
void Sys_CloseLog( const char *finalmsg );
|
||||||
void Sys_InitLog( void );
|
void Sys_InitLog( void );
|
||||||
void Sys_PrintLog( const char *pMsg );
|
void Sys_PrintLog( const char *pMsg );
|
||||||
int Sys_LogFileNo( void );
|
int Sys_LogFileNo( void );
|
||||||
|
|
|
@ -588,7 +588,7 @@ void Wcon_DestroyConsole( void )
|
||||||
// last text message into console or log
|
// last text message into console or log
|
||||||
Con_Reportf( "%s: Unloading xash.dll\n", __func__ );
|
Con_Reportf( "%s: Unloading xash.dll\n", __func__ );
|
||||||
|
|
||||||
Sys_CloseLog();
|
Sys_CloseLog( NULL );
|
||||||
|
|
||||||
if( !s_wcd.attached )
|
if( !s_wcd.attached )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue