Changeset 5166


Ignore:
Timestamp:
Feb 28, 2008, 5:51:54 PM (14 years ago)
Author:
charles
Message:

(gtk) use signal, instead of sigaction, for portability

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/main.c

    r5160 r5166  
    6767/* interval in milliseconds to check for stopped torrents and update display */
    6868#define EXIT_CHECK_INTERVAL     500
    69 
    70 /* number of fatal signals required to cause an immediate exit */
    71 #define SIGCOUNT_MAX            3
    7269
    7370#if GTK_CHECK_VERSION(2,8,0)
     
    124121static GtkUIManager * myUIManager = NULL;
    125122
    126 static sig_atomic_t global_sigcount = 0;
    127 
    128123static gboolean
    129124sendremote( GList * files, gboolean sendquit );
     
    155150static gboolean
    156151updatemodel(gpointer gdata);
    157 
    158 static void
    159 setupsighandlers(void);
    160 static void
    161 fatalsig(int sig);
    162152
    163153struct counts_data
     
    233223        cbdata->minimized = ( event->new_window_state & GDK_WINDOW_STATE_ICONIFIED ) ? 1 : 0;
    234224    }
     225}
     226
     227static sig_atomic_t global_sigcount = 0;
     228
     229static void
     230fatalsig( int sig )
     231{
     232    static const int SIGCOUNT_MAX = 3; /* revert to default handler after this many */
     233
     234    if( ++global_sigcount >= SIGCOUNT_MAX )
     235    {
     236        signal( sig, SIG_DFL );
     237        raise( sig );
     238    }
     239}
     240
     241
     242static void
     243setupsighandlers( void )
     244{
     245#ifdef G_OS_WIN32
     246  const int sigs[] = { SIGINT, SIGTERM };
     247#else
     248  const int sigs[] = { SIGHUP, SIGINT, SIGQUIT, SIGTERM };
     249#endif
     250  guint i;
     251
     252  for( i=0; i<G_N_ELEMENTS(sigs); ++i )
     253      signal( sigs[i], fatalsig );
    235254}
    236255
     
    11341153        updatemodel( data );
    11351154}
    1136 
    1137 
    1138 static void
    1139 setupsighandlers(void) {
    1140   int sigs[] = {SIGHUP, SIGINT, SIGQUIT, SIGTERM};
    1141   struct sigaction sa;
    1142   int ii;
    1143 
    1144   memset(&sa, 0,  sizeof(sa));
    1145   sa.sa_handler = fatalsig;
    1146   for(ii = 0; ii < ALEN(sigs); ii++)
    1147     sigaction(sigs[ii], &sa, NULL);
    1148 }
    1149 
    1150 static void
    1151 fatalsig(int sig) {
    1152   struct sigaction sa;
    1153 
    1154   if(SIGCOUNT_MAX <= ++global_sigcount) {
    1155     memset(&sa, 0,  sizeof(sa));
    1156     sa.sa_handler = SIG_DFL;
    1157     sigaction(sig, &sa, NULL);
    1158     raise(sig);
    1159   }
    1160 }
Note: See TracChangeset for help on using the changeset viewer.