aboutsummaryrefslogtreecommitdiffstats
path: root/unix.c
diff options
context:
space:
mode:
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 a3ead5a0..e879a4d4 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 = NULL;
struct sigaction sig, old;
memset( &global, 0, sizeof( global_t ) );
@@ -78,6 +80,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 );
}
@@ -113,6 +124,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 );
}