Changes in / [ec3e411:9fae35c]
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
bitlbee.c
rec3e411 r9fae35c 45 45 int i; 46 46 GIOChannel *ch; 47 FILE *fp;48 47 49 48 log_link( LOGLVL_ERROR, LOGOUTPUT_SYSLOG ); … … 105 104 else if( i != 0 ) 106 105 exit( 0 ); 107 106 close( 0 ); 107 close( 1 ); 108 close( 2 ); 108 109 chdir( "/" ); 109 110 /* Sometimes std* are already closed (for example when we're in a RESTARTed111 BitlBee process. So let's only close TTY-fds. */112 if( isatty( 0 ) ) close( 0 );113 if( isatty( 0 ) ) close( 1 );114 if( isatty( 0 ) ) close( 2 );115 110 } 116 111 #endif 117 118 if( global.conf->runmode == RUNMODE_FORKDAEMON )119 ipc_master_load_state();120 121 if( ( fp = fopen( global.conf->pidfile, "w" ) ) )122 {123 fprintf( fp, "%d\n", (int) getpid() );124 fclose( fp );125 }126 else127 {128 log_message( LOGLVL_WARNING, "Warning: Couldn't write PID to `%s'", global.conf->pidfile );129 }130 112 131 113 return( 0 ); … … 253 235 int new_socket = accept( global.listen_socket, (struct sockaddr *) &conn_info, &size ); 254 236 pid_t client_pid = 0; 255 256 if( new_socket == -1 )257 {258 log_message( LOGLVL_WARNING, "Could not accept new connection: %s", strerror( errno ) );259 return TRUE;260 }261 237 262 238 if( global.conf->runmode == RUNMODE_FORKDAEMON ) -
bitlbee.h
rec3e411 r9fae35c 121 121 char *helpfile; 122 122 GMainLoop *loop; 123 int restart;124 123 } global_t; 125 124 -
conf.c
rec3e411 r9fae35c 32 32 #include "ini.h" 33 33 #include "url.h" 34 #include "ipc.h"35 34 36 35 #include "protocols/proxy.h" … … 62 61 conf->configdir = g_strdup( CONFIG ); 63 62 conf->plugindir = g_strdup( PLUGINDIR ); 64 conf->pidfile = g_strdup( "/var/run/bitlbee.pid" );65 63 conf->motdfile = g_strdup( ETCDIR "/motd.txt" ); 66 64 conf->ping_interval = 180; … … 79 77 } 80 78 81 while( argc > 0 && ( opt = getopt( argc, argv, "i:p: P:nvIDFc:d:hR:" ) ) >= 0 )79 while( argc > 0 && ( opt = getopt( argc, argv, "i:p:nvIDFc:d:h" ) ) >= 0 ) 82 80 /* ^^^^ Just to make sure we skip this step from the REHASH handler. */ 83 81 { … … 94 92 } 95 93 conf->port = i; 96 }97 else if( opt == 'p' )98 {99 g_free( conf->pidfile );100 conf->pidfile = g_strdup( optarg );101 94 } 102 95 else if( opt == 'n' ) … … 149 142 return( NULL ); 150 143 } 151 else if( opt == 'R' )152 {153 /* We can't load the statefile yet (and should make very sure we do this154 only once), so set the filename here and load the state information155 when initializing ForkDaemon. (This option only makes sense in that156 mode anyway!) */157 ipc_master_set_statefile( optarg );158 }159 144 } 160 145 … … 190 175 else 191 176 conf->runmode = RUNMODE_INETD; 192 }193 else if( g_strcasecmp( ini->key, "pidfile" ) == 0 )194 {195 g_free( conf->pidfile );196 conf->pidfile = g_strdup( ini->value );197 177 } 198 178 else if( g_strcasecmp( ini->key, "daemoninterface" ) == 0 ) -
conf.h
rec3e411 r9fae35c 43 43 char *configdir; 44 44 char *plugindir; 45 char *pidfile;46 45 char *motdfile; 47 46 char *primary_storage; -
configure
rec3e411 r9fae35c 14 14 datadir='$prefix/share/bitlbee/' 15 15 config='/var/lib/bitlbee/' 16 pidfile='/var/run/bitlbee.pid'17 16 plugindir='$prefix/lib/bitlbee' 18 17 … … 47 46 --datadir=... $datadir 48 47 --plugindir=... $plugindir 49 --pidfile=... $pidfile50 48 --config=... $config 51 49 … … 76 74 config=`eval echo "$config/" | sed 's/\/\{1,\}/\//g'` 77 75 plugindir=`eval echo "$plugindir/" | sed 's/\/\{1,\}/\//g'` 78 pidfile=`eval echo "$pidfile/" | sed 's/\/\{1,\}/\//g'`79 76 80 77 cat<<EOF>Makefile.settings … … 86 83 DATADIR=$datadir 87 84 PLUGINDIR=$plugindir 88 PIDFILE=$pidfile89 85 CONFIG=$config 90 86 … … 108 104 #define VARDIR "$datadir" 109 105 #define PLUGINDIR "$plugindir" 110 #define PIDFILE "$pidfile"111 106 #define ARCH "$arch" 112 107 #define CPU "$cpu" -
ipc.c
rec3e411 r9fae35c 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * 4 * Copyright 2002-200 6Wilmer van der Gaast and others *4 * Copyright 2002-2004 Wilmer van der Gaast and others * 5 5 \********************************************************************/ 6 6 … … 30 30 31 31 GSList *child_list = NULL; 32 static char *statefile = NULL; 32 33 33 34 34 static void ipc_master_cmd_client( irc_t *data, char **cmd ) … … 36 36 struct bitlbee_child *child = (void*) data; 37 37 38 if( child && cmd[1])38 if( child ) 39 39 { 40 40 child->host = g_strdup( cmd[1] ); … … 43 43 } 44 44 45 if( g_strcasecmp( cmd[0], "CLIENT" ) == 0 ) 46 ipc_to_children_str( "OPERMSG :Client connecting (PID=%d): %s@%s (%s)\r\n", 47 child ? child->pid : -1, cmd[2], cmd[1], cmd[3] ); 45 ipc_to_children_str( "OPERMSG :Client connecting (PID=%d): %s@%s (%s)\r\n", 46 child ? child->pid : -1, cmd[2], cmd[1], cmd[3] ); 48 47 } 49 48 … … 75 74 } 76 75 77 void ipc_master_cmd_restart( irc_t *data, char **cmd )78 {79 struct bitlbee_child *child = (void*) data;80 81 if( global.conf->runmode != RUNMODE_FORKDAEMON )82 {83 /* Tell child that this is unsupported. */84 return;85 }86 87 global.restart = -1;88 bitlbee_shutdown( NULL );89 }90 91 76 static const command_t ipc_master_commands[] = { 92 77 { "client", 3, ipc_master_cmd_client, 0 }, 93 { "hello", 0, ipc_master_cmd_client, 0 },94 78 { "die", 0, ipc_master_cmd_die, 0 }, 95 79 { "wallops", 1, NULL, IPC_CMD_TO_CHILDREN }, … … 98 82 { "rehash", 0, ipc_master_cmd_rehash, 0 }, 99 83 { "kill", 2, NULL, IPC_CMD_TO_CHILDREN }, 100 { "restart", 0, ipc_master_cmd_restart, 0 },101 84 { NULL } 102 85 }; … … 157 140 irc_write( irc, ":%s!%s@%s KILL %s :%s", irc->mynick, irc->mynick, irc->myhost, irc->nick, cmd[2] ); 158 141 irc_abort( irc, 0, "Killed by operator: %s", cmd[2] ); 159 }160 161 static void ipc_child_cmd_hello( irc_t *irc, char **cmd )162 {163 if( irc->status < USTATUS_LOGGED_IN )164 ipc_to_master_str( "HELLO\r\n" );165 else166 ipc_to_master_str( "HELLO %s %s :%s\r\n", irc->host, irc->nick, irc->realname );167 142 } 168 143 … … 174 149 { "rehash", 0, ipc_child_cmd_rehash, 0 }, 175 150 { "kill", 2, ipc_child_cmd_kill, 0 }, 176 { "hello", 0, ipc_child_cmd_hello, 0 },177 151 { NULL } 178 152 }; … … 411 385 child_list = NULL; 412 386 } 413 414 char *ipc_master_save_state()415 {416 char *fn = g_strdup( "/tmp/bee-restart.XXXXXX" );417 int fd = mkstemp( fn );418 GSList *l;419 FILE *fp;420 int i;421 422 if( fd == -1 )423 {424 log_message( LOGLVL_ERROR, "Could not create temporary file: %s", strerror( errno ) );425 g_free( fn );426 return NULL;427 }428 429 /* This is more convenient now. */430 fp = fdopen( fd, "w" );431 432 for( l = child_list, i = 0; l; l = l->next )433 i ++;434 435 /* Number of client processes. */436 fprintf( fp, "%d\n", i );437 438 for( l = child_list; l; l = l->next )439 fprintf( fp, "%d %d\n", ((struct bitlbee_child*)l->data)->pid,440 ((struct bitlbee_child*)l->data)->ipc_fd );441 442 if( fclose( fp ) == 0 )443 {444 return fn;445 }446 else447 {448 unlink( fn );449 g_free( fn );450 return NULL;451 }452 }453 454 void ipc_master_set_statefile( char *fn )455 {456 statefile = g_strdup( fn );457 }458 459 int ipc_master_load_state()460 {461 struct bitlbee_child *child;462 FILE *fp;463 int i, n;464 465 if( statefile == NULL )466 return 0;467 fp = fopen( statefile, "r" );468 unlink( statefile ); /* Why do it later? :-) */469 if( fp == NULL )470 return 0;471 472 if( fscanf( fp, "%d", &n ) != 1 )473 {474 log_message( LOGLVL_WARNING, "Could not import state information for child processes." );475 fclose( fp );476 return 0;477 }478 479 log_message( LOGLVL_INFO, "Importing information for %d child processes.", n );480 for( i = 0; i < n; i ++ )481 {482 child = g_new0( struct bitlbee_child, 1 );483 484 if( fscanf( fp, "%d %d", &child->pid, &child->ipc_fd ) != 2 )485 {486 log_message( LOGLVL_WARNING, "Unexpected end of file: Only processed %d clients.", i );487 g_free( child );488 fclose( fp );489 return 0;490 }491 child->ipc_inpa = gaim_input_add( child->ipc_fd, GAIM_INPUT_READ, ipc_master_read, child );492 493 child_list = g_slist_append( child_list, child );494 }495 496 ipc_to_children_str( "HELLO\r\n" );497 ipc_to_children_str( "OPERMSG :New BitlBee master process started (version " BITLBEE_VERSION ")\r\n" );498 499 return 1;500 } -
ipc.h
rec3e411 r9fae35c 54 54 void ipc_master_cmd_rehash( irc_t *data, char **cmd ); 55 55 56 char *ipc_master_save_state();57 void ipc_master_set_statefile( char *fn );58 int ipc_master_load_state();59 60 56 61 57 extern GSList *child_list; -
irc_commands.c
rec3e411 r9fae35c 573 573 { "lilo", 1, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, 574 574 { "rehash", 0, irc_cmd_rehash, IRC_CMD_OPER_ONLY }, 575 { "restart", 0, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },576 575 { "kill", 2, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, 577 576 { NULL } -
protocols/msn/msn.c
rec3e411 r9fae35c 84 84 { 85 85 m = l->data; 86 87 serv_got_crap( gc, "Warning: Closing down MSN connection with unsent message to %s, you'll have to resend it.", m->who );88 86 g_free( m->who ); 89 87 g_free( m->text ); … … 91 89 } 92 90 g_slist_free( md->msgq ); 91 92 serv_got_crap( gc, "Warning: Closing down MSN connection with unsent message(s), you'll have to resend them." ); 93 93 } 94 94 -
protocols/msn/sb.c
rec3e411 r9fae35c 213 213 { 214 214 m = l->data; 215 216 215 g_free( m->who ); 217 216 g_free( m->text ); … … 220 219 g_slist_free( sb->msgq ); 221 220 222 serv_got_crap( gc, "Warning: Closing down MSN switchboard connection with " 223 "unsent message to %s, you'll have to resend it.", 224 m->who ? m->who : "(unknown)" ); 221 serv_got_crap( gc, "Warning: Closing down MSN switchboard connection with unsent message(s), you'll have to resend them." ); 225 222 } 226 223 -
root_commands.c
rec3e411 r9fae35c 601 601 { 602 602 set_setstr( irc, cmd[1], cmd[2] ); 603 604 if( ( strcmp( cmd[2], "=" ) ) == 0 && cmd[3] )605 irc_usermsg( irc, "Warning: Correct syntax: \002set <variable> <value>\002 (without =)" );606 603 } 607 604 if( cmd[1] ) /* else 'forgotten' on purpose.. Must show new value after changing */ -
unix.c
rec3e411 r9fae35c 29 29 #include "protocols/nogaim.h" 30 30 #include "help.h" 31 #include "ipc.h"32 31 #include <signal.h> 33 32 #include <unistd.h> … … 39 38 static void sighandler( int signal ); 40 39 41 int main( int argc, char *argv[] , char **envp)40 int main( int argc, char *argv[] ) 42 41 { 43 42 int i = 0; 44 char *old_cwd;45 43 struct sigaction sig, old; 46 44 … … 75 73 else if( global.conf->runmode == RUNMODE_FORKDAEMON ) 76 74 { 77 /* In case the operator requests a restart, we need this. */78 old_cwd = g_malloc( 256 );79 if( getcwd( old_cwd, 255 ) == NULL )80 {81 log_message( LOGLVL_WARNING, "Could not save current directory: %s", strerror( errno ) );82 g_free( old_cwd );83 old_cwd = NULL;84 }85 86 75 i = bitlbee_daemon_init(); 87 76 log_message( LOGLVL_INFO, "Bitlbee %s starting in forking daemon mode.", BITLBEE_VERSION ); … … 118 107 119 108 g_main_run( global.loop ); 120 121 if( global.restart )122 {123 char *fn = ipc_master_save_state();124 char **args;125 int n, i;126 127 chdir( old_cwd );128 129 n = 0;130 args = g_new0( char *, argc + 3 );131 args[n++] = argv[0];132 if( fn )133 {134 args[n++] = "-R";135 args[n++] = fn;136 }137 for( i = 1; argv[i] && i < argc; i ++ )138 {139 if( strcmp( argv[i], "-R" ) == 0 )140 i += 2;141 142 args[n++] = argv[i];143 }144 145 close( global.listen_socket );146 147 execve( args[0], args, envp );148 }149 109 150 110 return( 0 );
Note: See TracChangeset
for help on using the changeset viewer.