mirror of
https://github.com/transmission/transmission
synced 2024-12-24 08:43:27 +00:00
(trunk gtk) #2454: gtk client handles SIGINT (ctrl-c) oddly
This commit is contained in:
parent
b32e5cc25d
commit
8bfdf85ac3
1 changed files with 17 additions and 18 deletions
35
gtk/main.c
35
gtk/main.c
|
@ -259,32 +259,29 @@ onMainWindowSizeAllocated( GtkWidget * window,
|
|||
}
|
||||
|
||||
static sig_atomic_t global_sigcount = 0;
|
||||
static struct cbdata * sighandler_cbdata = NULL;
|
||||
|
||||
static void
|
||||
fatalsig( int sig )
|
||||
signal_handler( int sig )
|
||||
{
|
||||
/* revert to default handler after this many */
|
||||
static const int SIGCOUNT_MAX = 3;
|
||||
|
||||
if( ++global_sigcount >= SIGCOUNT_MAX )
|
||||
if( ++global_sigcount > 1 )
|
||||
{
|
||||
signal( sig, SIG_DFL );
|
||||
raise( sig );
|
||||
}
|
||||
else switch( sig )
|
||||
{
|
||||
case SIGINT:
|
||||
g_message( _( "Got signal %d; trying to shut down cleanly. Do it again if it gets stuck." ), sig );
|
||||
doAction( "quit", sighandler_cbdata );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
setupsighandlers( void )
|
||||
{
|
||||
#ifdef G_OS_WIN32
|
||||
const int sigs[] = { SIGINT, SIGTERM };
|
||||
#else
|
||||
const int sigs[] = { SIGHUP, SIGINT, SIGQUIT, SIGTERM };
|
||||
#endif
|
||||
guint i;
|
||||
|
||||
for( i = 0; i < G_N_ELEMENTS( sigs ); ++i )
|
||||
signal( sigs[i], fatalsig );
|
||||
signal( SIGINT, signal_handler );
|
||||
}
|
||||
|
||||
static tr_rpc_callback_status
|
||||
|
@ -434,11 +431,13 @@ main( int argc, char ** argv )
|
|||
tr_session * session;
|
||||
struct cbdata * cbdata = g_new0( struct cbdata, 1 );
|
||||
|
||||
sighandler_cbdata = cbdata;
|
||||
|
||||
/* ensure the directories are created */
|
||||
if(( str = pref_string_get( PREF_KEY_DIR_WATCH )))
|
||||
gtr_mkdir_with_parents( str, 0777 );
|
||||
if(( str = pref_string_get( TR_PREFS_KEY_DOWNLOAD_DIR )))
|
||||
gtr_mkdir_with_parents( str, 0777 );
|
||||
if(( str = pref_string_get( PREF_KEY_DIR_WATCH )))
|
||||
gtr_mkdir_with_parents( str, 0777 );
|
||||
if(( str = pref_string_get( TR_PREFS_KEY_DOWNLOAD_DIR )))
|
||||
gtr_mkdir_with_parents( str, 0777 );
|
||||
|
||||
/* initialize the libtransmission session */
|
||||
session = tr_sessionInit( "gtk", configDir, TRUE, pref_get_all( ) );
|
||||
|
|
Loading…
Reference in a new issue