Changeset devel,406

Show
Ignore:
Timestamp:
2008-06-29T12:47:39Z (2 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
branch-nick:
devel
revision id:
wilmer@gaast.net-20080629124739-q2rjwq2idog17d31
Message:

Now using an environment variable instead of a flag to pass state info when
restarting the ForkDaemon. Preparing for a proper fallback when execv()
fails. (Bug #425)

Location:
devel
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • devel/bitlbee.c

    r380 r406  
    118118         
    119119        if( global.conf->runmode == RUNMODE_FORKDAEMON ) 
    120                 ipc_master_load_state(); 
     120                ipc_master_load_state( getenv( "_BITLBEE_RESTART_STATE" ) ); 
    121121 
    122122        if( global.conf->runmode == RUNMODE_DAEMON || global.conf->runmode == RUNMODE_FORKDAEMON ) 
  • devel/conf.c

    r384 r406  
    7878        } 
    7979         
    80         while( argc > 0 && ( opt = getopt( argc, argv, "i:p:P:nvIDFc:d:hR:u:" ) ) >= 0 ) 
     80        while( argc > 0 && ( opt = getopt( argc, argv, "i:p:P:nvIDFc:d:hu:" ) ) >= 0 ) 
    8181        /*     ^^^^ Just to make sure we skip this step from the REHASH handler. */ 
    8282        { 
     
    145145                                "  -h  Show this help page.\n" ); 
    146146                        return NULL; 
    147                 } 
    148                 else if( opt == 'R' ) 
    149                 { 
    150                         /* We can't load the statefile yet (and should make very sure we do this 
    151                            only once), so set the filename here and load the state information 
    152                            when initializing ForkDaemon. (This option only makes sense in that 
    153                            mode anyway!) */ 
    154                         ipc_master_set_statefile( optarg ); 
    155147                } 
    156148                else if( opt == 'u' ) 
  • devel/ipc.c

    r404 r406  
    3333 
    3434GSList *child_list = NULL; 
    35 static char *statefile = NULL; 
    3635 
    3736static void ipc_master_cmd_client( irc_t *data, char **cmd ) 
     
    501500} 
    502501 
    503 void ipc_master_set_statefile( char *fn ) 
    504 { 
    505         statefile = g_strdup( fn ); 
    506 } 
    507  
    508502 
    509503static gboolean new_ipc_client( gpointer data, gint serversock, b_input_condition cond ) 
     
    566560#endif 
    567561 
    568 int ipc_master_load_state() 
     562int ipc_master_load_state( char *statefile ) 
    569563{ 
    570564        struct bitlbee_child *child; 
     
    574568        if( statefile == NULL ) 
    575569                return 0; 
     570         
    576571        fp = fopen( statefile, "r" ); 
    577572        unlink( statefile );    /* Why do it later? :-) */ 
  • devel/ipc.h

    r341 r406  
    5858 
    5959char *ipc_master_save_state(); 
    60 void ipc_master_set_statefile( char *fn ); 
    61 int ipc_master_load_state(); 
     60int ipc_master_load_state( char *statefile ); 
    6261int ipc_master_listen_socket(); 
    6362 
  • devel/unix.c

    r72.5.4 r406  
    4040static void sighandler( int signal ); 
    4141 
    42 int main( int argc, char *argv[], char **envp ) 
     42int main( int argc, char *argv[] ) 
    4343{ 
    4444        int i = 0; 
     
    135135        { 
    136136                char *fn = ipc_master_save_state(); 
    137                 char **args; 
    138                 int n, i; 
    139137                 
    140138                chdir( old_cwd ); 
    141139                 
    142                 n = 0; 
    143                 args = g_new0( char *, argc + 3 ); 
    144                 args[n++] = argv[0]; 
    145                 if( fn ) 
    146                 { 
    147                         args[n++] = "-R"; 
    148                         args[n++] = fn; 
    149                 } 
    150                 for( i = 1; argv[i] && i < argc; i ++ ) 
    151                 { 
    152                         if( strcmp( argv[i], "-R" ) == 0 ) 
    153                                 i += 2; 
    154                          
    155                         args[n++] = argv[i]; 
    156                 } 
     140                setenv( "_BITLBEE_RESTART_STATE", fn, 1 ); 
     141                g_free( fn ); 
    157142                 
    158143                close( global.listen_socket ); 
    159144                 
    160                 execve( args[0], args, envp ); 
     145                if( execv( argv[0], argv ) == -1 ) 
     146                        /* Apparently the execve() failed, so let's just 
     147                           jump back into our own/current main(). */ 
     148                        /* Need more cleanup code to make this work. */ 
     149                        return 1; /* main( argc, argv ); */ 
    161150        } 
    162151