mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +01:00
Install a no-op TERM handler at first then replace later with one that
just exits main loop. Do cleanup/file saving on exit from mainloop. Fixes occasional crash where TERM came in before we were setup to cleanup.
This commit is contained in:
parent
df1ec1628a
commit
00cdbc97d3
3 changed files with 46 additions and 22 deletions
|
@ -475,22 +475,6 @@ showStatus( CursesAppGlobals* globals )
|
||||||
static XP_Bool
|
static XP_Bool
|
||||||
handleQuit( CursesAppGlobals* globals )
|
handleQuit( CursesAppGlobals* globals )
|
||||||
{
|
{
|
||||||
if ( !!globals->cGlobals.params->fileName ) {
|
|
||||||
XWStreamCtxt* outStream;
|
|
||||||
|
|
||||||
outStream = mem_stream_make(
|
|
||||||
MPPARM(globals->cGlobals.params->util->mpool)
|
|
||||||
globals->cGlobals.params->vtMgr,
|
|
||||||
&globals->cGlobals, 0, writeToFile );
|
|
||||||
stream_open( outStream );
|
|
||||||
|
|
||||||
game_saveToStream( &globals->cGlobals.game,
|
|
||||||
&globals->cGlobals.params->gi,
|
|
||||||
outStream );
|
|
||||||
|
|
||||||
stream_destroy( outStream );
|
|
||||||
}
|
|
||||||
|
|
||||||
globals->timeToExit = XP_TRUE;
|
globals->timeToExit = XP_TRUE;
|
||||||
return XP_TRUE;
|
return XP_TRUE;
|
||||||
} /* handleQuit */
|
} /* handleQuit */
|
||||||
|
@ -1531,6 +1515,10 @@ cursesmain( XP_Bool isServer, LaunchParams* params )
|
||||||
&g_globals.cp, &procs );
|
&g_globals.cp, &procs );
|
||||||
|
|
||||||
stream_destroy( stream );
|
stream_destroy( stream );
|
||||||
|
|
||||||
|
if ( !isServer && params->gi.serverRole == SERVER_ISSERVER ) {
|
||||||
|
isServer = XP_TRUE;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
game_makeNewGame( MEMPOOL &g_globals.cGlobals.game, ¶ms->gi,
|
game_makeNewGame( MEMPOOL &g_globals.cGlobals.game, ¶ms->gi,
|
||||||
params->util, (DrawCtx*)g_globals.draw,
|
params->util, (DrawCtx*)g_globals.draw,
|
||||||
|
@ -1620,6 +1608,22 @@ cursesmain( XP_Bool isServer, LaunchParams* params )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !!g_globals.cGlobals.params->fileName ) {
|
||||||
|
XWStreamCtxt* outStream;
|
||||||
|
|
||||||
|
outStream = mem_stream_make(
|
||||||
|
MPPARM(g_globals.cGlobals.params->util->mpool)
|
||||||
|
g_globals.cGlobals.params->vtMgr,
|
||||||
|
&g_globals.cGlobals, 0, writeToFile );
|
||||||
|
stream_open( outStream );
|
||||||
|
|
||||||
|
game_saveToStream( &g_globals.cGlobals.game,
|
||||||
|
&g_globals.cGlobals.params->gi,
|
||||||
|
outStream );
|
||||||
|
|
||||||
|
stream_destroy( outStream );
|
||||||
|
}
|
||||||
|
|
||||||
game_dispose( &g_globals.cGlobals.game ); /* takes care of the dict */
|
game_dispose( &g_globals.cGlobals.game ); /* takes care of the dict */
|
||||||
gi_disposePlayerInfo( MEMPOOL &g_globals.cGlobals.params->gi );
|
gi_disposePlayerInfo( MEMPOOL &g_globals.cGlobals.params->gi );
|
||||||
|
|
||||||
|
|
|
@ -649,7 +649,13 @@ handle_client_event( GtkWidget *widget, GdkEventClient *event,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
quit( void* XP_UNUSED(dunno), GtkAppGlobals* globals )
|
quit( void )
|
||||||
|
{
|
||||||
|
gtk_main_quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cleanup( GtkAppGlobals* globals )
|
||||||
{
|
{
|
||||||
if ( !!globals->cGlobals.params->fileName ) {
|
if ( !!globals->cGlobals.params->fileName ) {
|
||||||
XWStreamCtxt* outStream;
|
XWStreamCtxt* outStream;
|
||||||
|
@ -680,9 +686,7 @@ quit( void* XP_UNUSED(dunno), GtkAppGlobals* globals )
|
||||||
#ifdef XWFEATURE_RELAY
|
#ifdef XWFEATURE_RELAY
|
||||||
linux_close_socket( &globals->cGlobals );
|
linux_close_socket( &globals->cGlobals );
|
||||||
#endif
|
#endif
|
||||||
|
} /* cleanup */
|
||||||
gtk_main_quit();
|
|
||||||
} /* quit */
|
|
||||||
|
|
||||||
GtkWidget*
|
GtkWidget*
|
||||||
makeAddSubmenu( GtkWidget* menubar, gchar* label )
|
makeAddSubmenu( GtkWidget* menubar, gchar* label )
|
||||||
|
@ -1328,7 +1332,7 @@ gtk_util_notifyGameOver( XW_UtilCtxt* uc )
|
||||||
|
|
||||||
if ( cGlobals->params->quitAfter >= 0 ) {
|
if ( cGlobals->params->quitAfter >= 0 ) {
|
||||||
sleep( cGlobals->params->quitAfter );
|
sleep( cGlobals->params->quitAfter );
|
||||||
quit( NULL, globals );
|
quit();
|
||||||
} else if ( cGlobals->params->undoWhenDone ) {
|
} else if ( cGlobals->params->undoWhenDone ) {
|
||||||
server_handleUndo( cGlobals->game.server );
|
server_handleUndo( cGlobals->game.server );
|
||||||
board_draw( cGlobals->game.board );
|
board_draw( cGlobals->game.board );
|
||||||
|
@ -2060,7 +2064,8 @@ static GtkAppGlobals* g_globals_for_signal;
|
||||||
static void
|
static void
|
||||||
handle_sigintterm( int XP_UNUSED(sig) )
|
handle_sigintterm( int XP_UNUSED(sig) )
|
||||||
{
|
{
|
||||||
quit( NULL, g_globals_for_signal );
|
LOG_FUNC();
|
||||||
|
gtk_main_quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -2218,6 +2223,8 @@ gtkmain( LaunchParams* params, int argc, char *argv[] )
|
||||||
|
|
||||||
/* MONCONTROL(1); */
|
/* MONCONTROL(1); */
|
||||||
|
|
||||||
|
cleanup( &globals );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} /* gtkmain */
|
} /* gtkmain */
|
||||||
|
|
||||||
|
|
|
@ -728,6 +728,12 @@ parsePair( const char* optarg, XP_U16* min, XP_U16* max )
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void
|
||||||
|
tmp_noop_sigintterm( int XP_UNUSED(sig) )
|
||||||
|
{
|
||||||
|
LOG_FUNC();
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main( int argc, char** argv )
|
main( int argc, char** argv )
|
||||||
{
|
{
|
||||||
|
@ -741,6 +747,13 @@ main( int argc, char** argv )
|
||||||
unsigned int seed = defaultRandomSeed();
|
unsigned int seed = defaultRandomSeed();
|
||||||
LaunchParams mainParams;
|
LaunchParams mainParams;
|
||||||
XP_U16 robotCount = 0;
|
XP_U16 robotCount = 0;
|
||||||
|
|
||||||
|
/* install a no-op signal handler. Later curses- or gtk-specific code
|
||||||
|
will install one that does the right thing in that context */
|
||||||
|
|
||||||
|
struct sigaction act = { .sa_handler = tmp_noop_sigintterm };
|
||||||
|
sigaction( SIGINT, &act, NULL );
|
||||||
|
sigaction( SIGTERM, &act, NULL );
|
||||||
|
|
||||||
CommsConnType conType = COMMS_CONN_NONE;
|
CommsConnType conType = COMMS_CONN_NONE;
|
||||||
#ifdef XWFEATURE_SMS
|
#ifdef XWFEATURE_SMS
|
||||||
|
|
Loading…
Reference in a new issue