diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2006-02-02 14:59:14 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2006-02-02 14:59:14 +0100 |
commit | 1d2e3c2ee2fb4c12ad25832b93ae9513d042717a (patch) | |
tree | ea7c2a7a03f39ae8dcb1de0d98d35aaa6c7b19d3 /unix.c | |
parent | 34b17d9b8901b72439167b99d780c481ce420e33 (diff) | |
parent | a49dcd5c3c6b79470ad71dc45ccf29f65ba2a7f9 (diff) |
Added RESTART command for easier upgrades without losing IPC connections.
(Obviously only works well for forking daemon mode.)
Diffstat (limited to 'unix.c')
-rw-r--r-- | unix.c | 42 |
1 files changed, 41 insertions, 1 deletions
@@ -28,6 +28,7 @@ #include "crypting.h" #include "protocols/nogaim.h" #include "help.h" +#include "ipc.h" #include <signal.h> #include <unistd.h> #include <sys/time.h> @@ -37,9 +38,10 @@ global_t global; /* Against global namespace pollution */ static void sighandler( int signal ); -int main( int argc, char *argv[] ) +int main( int argc, char *argv[], char **envp ) { int i = 0; + char *old_cwd; struct sigaction sig, old; memset( &global, 0, sizeof( global_t ) ); @@ -72,6 +74,15 @@ int main( int argc, char *argv[] ) } else if( global.conf->runmode == RUNMODE_FORKDAEMON ) { + /* In case the operator requests a restart, we need this. */ + old_cwd = g_malloc( 256 ); + if( getcwd( old_cwd, 255 ) == NULL ) + { + log_message( LOGLVL_WARNING, "Could not save current directory: %s", strerror( errno ) ); + g_free( old_cwd ); + old_cwd = NULL; + } + i = bitlbee_daemon_init(); log_message( LOGLVL_INFO, "Bitlbee %s starting in forking daemon mode.", BITLBEE_VERSION ); } @@ -107,6 +118,35 @@ int main( int argc, char *argv[] ) g_main_run( global.loop ); + if( global.restart ) + { + char *fn = ipc_master_save_state(); + char **args; + int n, i; + + chdir( old_cwd ); + + n = 0; + args = g_new0( char *, argc + 3 ); + args[n++] = argv[0]; + if( fn ) + { + args[n++] = "-R"; + args[n++] = fn; + } + for( i = 1; argv[i] && i < argc; i ++ ) + { + if( strcmp( argv[i], "-R" ) == 0 ) + i += 2; + + args[n++] = argv[i]; + } + + close( global.listen_socket ); + + execve( args[0], args, envp ); + } + return( 0 ); } |