Changeset 9196 for trunk/gtk/main.c


Ignore:
Timestamp:
Sep 27, 2009, 8:32:32 PM (13 years ago)
Author:
charles
Message:

(trunk gtk) #2454: gtk client handles SIGINT (ctrl-c) oddly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/main.c

    r9130 r9196  
    260260
    261261static sig_atomic_t global_sigcount = 0;
    262 
    263 static void
    264 fatalsig( int sig )
    265 {
    266     /* revert to default handler after this many */
    267     static const int SIGCOUNT_MAX = 3;
    268 
    269     if( ++global_sigcount >= SIGCOUNT_MAX )
     262static struct cbdata * sighandler_cbdata = NULL;
     263
     264static void
     265signal_handler( int sig )
     266{
     267    if( ++global_sigcount > 1 )
    270268    {
    271269        signal( sig, SIG_DFL );
    272270        raise( sig );
    273271    }
     272    else switch( sig )
     273    {
     274        case SIGINT:
     275            g_message( _( "Got signal %d; trying to shut down cleanly.  Do it again if it gets stuck." ), sig );
     276            doAction( "quit", sighandler_cbdata );
     277            break;
     278    }
    274279}
    275280
     
    277282setupsighandlers( void )
    278283{
    279 #ifdef G_OS_WIN32
    280     const int sigs[] = { SIGINT, SIGTERM };
    281 #else
    282     const int sigs[] = { SIGHUP, SIGINT, SIGQUIT, SIGTERM };
    283 #endif
    284     guint     i;
    285 
    286     for( i = 0; i < G_N_ELEMENTS( sigs ); ++i )
    287         signal( sigs[i], fatalsig );
     284    signal( SIGINT, signal_handler );
    288285}
    289286
     
    435432        struct cbdata * cbdata = g_new0( struct cbdata, 1 );
    436433
     434        sighandler_cbdata = cbdata;
     435
    437436        /* ensure the directories are created */
    438        if(( str = pref_string_get( PREF_KEY_DIR_WATCH )))
    439            gtr_mkdir_with_parents( str, 0777 );
    440        if(( str = pref_string_get( TR_PREFS_KEY_DOWNLOAD_DIR )))
    441            gtr_mkdir_with_parents( str, 0777 );
     437        if(( str = pref_string_get( PREF_KEY_DIR_WATCH )))
     438            gtr_mkdir_with_parents( str, 0777 );
     439        if(( str = pref_string_get( TR_PREFS_KEY_DOWNLOAD_DIR )))
     440            gtr_mkdir_with_parents( str, 0777 );
    442441
    443442        /* initialize the libtransmission session */
Note: See TracChangeset for help on using the changeset viewer.