Changeset a4dc9f7 for unix.c


Ignore:
Timestamp:
2006-03-01T22:48:37Z (18 years ago)
Author:
Jelmer Vernooij <jelmer@…>
Branches:
master
Children:
46ad029
Parents:
8e419cb (diff), 9a1555d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

[merge] Wilmer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • unix.c

    r8e419cb ra4dc9f7  
    2929#include "protocols/nogaim.h"
    3030#include "help.h"
     31#include "ipc.h"
    3132#include <signal.h>
    3233#include <unistd.h>
     
    3839static void sighandler( int signal );
    3940
    40 int main( int argc, char *argv[] )
     41int main( int argc, char *argv[], char **envp )
    4142{
    4243        int i = 0;
     44        char *old_cwd = NULL;
    4345        struct sigaction sig, old;
    4446       
     
    7981        else if( global.conf->runmode == RUNMODE_FORKDAEMON )
    8082        {
     83                /* In case the operator requests a restart, we need this. */
     84                old_cwd = g_malloc( 256 );
     85                if( getcwd( old_cwd, 255 ) == NULL )
     86                {
     87                        log_message( LOGLVL_WARNING, "Could not save current directory: %s", strerror( errno ) );
     88                        g_free( old_cwd );
     89                        old_cwd = NULL;
     90                }
     91               
    8192                i = bitlbee_daemon_init();
    8293                log_message( LOGLVL_INFO, "Bitlbee %s starting in forking daemon mode.", BITLBEE_VERSION );
     
    114125        g_main_run( global.loop );
    115126       
     127        if( global.restart )
     128        {
     129                char *fn = ipc_master_save_state();
     130                char **args;
     131                int n, i;
     132               
     133                chdir( old_cwd );
     134               
     135                n = 0;
     136                args = g_new0( char *, argc + 3 );
     137                args[n++] = argv[0];
     138                if( fn )
     139                {
     140                        args[n++] = "-R";
     141                        args[n++] = fn;
     142                }
     143                for( i = 1; argv[i] && i < argc; i ++ )
     144                {
     145                        if( strcmp( argv[i], "-R" ) == 0 )
     146                                i += 2;
     147                       
     148                        args[n++] = argv[i];
     149                }
     150               
     151                close( global.listen_socket );
     152               
     153                execve( args[0], args, envp );
     154        }
     155       
    116156        return( 0 );
    117157}
Note: See TracChangeset for help on using the changeset viewer.