aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2008-06-29 13:47:39 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2008-06-29 13:47:39 +0100
commitcd63d5822e76a6126bb3017567c9ce2869a44e0b (patch)
tree58177973085309fd2e3089864037c33cccaafe94
parent1145964911d0d7dd5145de6f7b9d4ed8aeeacd79 (diff)
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)
-rw-r--r--bitlbee.c2
-rw-r--r--conf.c10
-rw-r--r--ipc.c9
-rw-r--r--ipc.h3
-rw-r--r--unix.c27
5 files changed, 13 insertions, 38 deletions
diff --git a/bitlbee.c b/bitlbee.c
index 17431546..d8a6a5a7 100644
--- a/bitlbee.c
+++ b/bitlbee.c
@@ -117,7 +117,7 @@ int bitlbee_daemon_init()
#endif
if( global.conf->runmode == RUNMODE_FORKDAEMON )
- ipc_master_load_state();
+ ipc_master_load_state( getenv( "_BITLBEE_RESTART_STATE" ) );
if( global.conf->runmode == RUNMODE_DAEMON || global.conf->runmode == RUNMODE_FORKDAEMON )
ipc_master_listen_socket();
diff --git a/conf.c b/conf.c
index 2bdead65..909d331a 100644
--- a/conf.c
+++ b/conf.c
@@ -77,7 +77,7 @@ conf_t *conf_load( int argc, char *argv[] )
at a *valid* configuration file. */
}
- while( argc > 0 && ( opt = getopt( argc, argv, "i:p:P:nvIDFc:d:hR:u:" ) ) >= 0 )
+ while( argc > 0 && ( opt = getopt( argc, argv, "i:p:P:nvIDFc:d:hu:" ) ) >= 0 )
/* ^^^^ Just to make sure we skip this step from the REHASH handler. */
{
if( opt == 'i' )
@@ -145,14 +145,6 @@ conf_t *conf_load( int argc, char *argv[] )
" -h Show this help page.\n" );
return NULL;
}
- else if( opt == 'R' )
- {
- /* We can't load the statefile yet (and should make very sure we do this
- only once), so set the filename here and load the state information
- when initializing ForkDaemon. (This option only makes sense in that
- mode anyway!) */
- ipc_master_set_statefile( optarg );
- }
else if( opt == 'u' )
{
g_free( conf->user );
diff --git a/ipc.c b/ipc.c
index 9121026a..5232832e 100644
--- a/ipc.c
+++ b/ipc.c
@@ -32,7 +32,6 @@
#endif
GSList *child_list = NULL;
-static char *statefile = NULL;
static void ipc_master_cmd_client( irc_t *data, char **cmd )
{
@@ -500,11 +499,6 @@ char *ipc_master_save_state()
}
}
-void ipc_master_set_statefile( char *fn )
-{
- statefile = g_strdup( fn );
-}
-
static gboolean new_ipc_client( gpointer data, gint serversock, b_input_condition cond )
{
@@ -565,7 +559,7 @@ int ipc_master_listen_socket()
/* FIXME: Open named pipe \\.\BITLBEE */
#endif
-int ipc_master_load_state()
+int ipc_master_load_state( char *statefile )
{
struct bitlbee_child *child;
FILE *fp;
@@ -573,6 +567,7 @@ int ipc_master_load_state()
if( statefile == NULL )
return 0;
+
fp = fopen( statefile, "r" );
unlink( statefile ); /* Why do it later? :-) */
if( fp == NULL )
diff --git a/ipc.h b/ipc.h
index f3d24614..0e71c520 100644
--- a/ipc.h
+++ b/ipc.h
@@ -57,8 +57,7 @@ void ipc_to_children_str( char *format, ... ) G_GNUC_PRINTF( 1, 2 );
void ipc_master_cmd_rehash( irc_t *data, char **cmd );
char *ipc_master_save_state();
-void ipc_master_set_statefile( char *fn );
-int ipc_master_load_state();
+int ipc_master_load_state( char *statefile );
int ipc_master_listen_socket();
extern GSList *child_list;
diff --git a/unix.c b/unix.c
index d25aeb2e..336b49c4 100644
--- a/unix.c
+++ b/unix.c
@@ -39,7 +39,7 @@ global_t global; /* Against global namespace pollution */
static void sighandler( int signal );
-int main( int argc, char *argv[], char **envp )
+int main( int argc, char *argv[] )
{
int i = 0;
char *old_cwd = NULL;
@@ -134,30 +134,19 @@ int main( int argc, char *argv[], char **envp )
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];
- }
+ setenv( "_BITLBEE_RESTART_STATE", fn, 1 );
+ g_free( fn );
close( global.listen_socket );
- execve( args[0], args, envp );
+ if( execv( argv[0], argv ) == -1 )
+ /* Apparently the execve() failed, so let's just
+ jump back into our own/current main(). */
+ /* Need more cleanup code to make this work. */
+ return 1; /* main( argc, argv ); */
}
return( 0 );