aboutsummaryrefslogtreecommitdiffstats
path: root/unix.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2006-01-21 23:31:10 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2006-01-21 23:31:10 +0100
commit54879ab3b2cbcaf1c9114bddd85ec5d4dc097915 (patch)
tree34cc9e33fc6343fd90141aa0b1faaee57debbe61 /unix.c
parentf73b9697f9be18e04ec7458634520f9dd2e2432f (diff)
parentf1d38f20f760376f43b90a105486cf3ff2fbf2c4 (diff)
Added RESTART command (only for ForkDaemon mode) for easier upgrades.
Diffstat (limited to 'unix.c')
-rw-r--r--unix.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/unix.c b/unix.c
index fafa828e..e59c341a 100644
--- a/unix.c
+++ b/unix.c
@@ -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 );
}