Changes in unix.c [b73ac9c:58bc4e6]
Legend:
- Unmodified
- Added
- Removed
-
unix.c
rb73ac9c r58bc4e6 29 29 #include "protocols/nogaim.h" 30 30 #include "help.h" 31 #include "ipc.h" 31 32 #include <signal.h> 32 33 #include <unistd.h> 33 34 #include <sys/time.h> 35 #include <sys/wait.h> 34 36 35 37 global_t global; /* Against global namespace pollution */ … … 37 39 static void sighandler( int signal ); 38 40 39 int main( int argc, char *argv[] )41 int main( int argc, char *argv[], char **envp ) 40 42 { 41 43 int i = 0; 44 char *old_cwd = NULL; 42 45 struct sigaction sig, old; 43 46 … … 46 49 global.loop = g_main_new( FALSE ); 47 50 48 log_init( ); 49 nogaim_init( ); 50 51 log_init(); 52 53 nogaim_init(); 54 51 55 CONF_FILE = g_strdup( CONF_FILE_DEF ); 52 56 … … 69 73 log_message( LOGLVL_INFO, "Bitlbee %s starting in daemon mode.", BITLBEE_VERSION ); 70 74 } 75 else if( global.conf->runmode == RUNMODE_FORKDAEMON ) 76 { 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 i = bitlbee_daemon_init(); 87 log_message( LOGLVL_INFO, "Bitlbee %s starting in forking daemon mode.", BITLBEE_VERSION ); 88 } 71 89 if( i != 0 ) 72 90 return( i ); 73 91 74 global.storage = storage_init( global.conf->primary_storage, 75 global.conf->migrate_storage ); 92 global.storage = storage_init( global.conf->primary_storage, global.conf->migrate_storage ); 76 93 if ( global.storage == NULL) { 77 94 log_message( LOGLVL_ERROR, "Unable to load storage backend '%s'", global.conf->primary_storage ); … … 83 100 memset( &sig, 0, sizeof( sig ) ); 84 101 sig.sa_handler = sighandler; 102 sigaction( SIGCHLD, &sig, &old ); 85 103 sigaction( SIGPIPE, &sig, &old ); 86 104 sig.sa_flags = SA_RESETHAND; … … 101 119 g_main_run( global.loop ); 102 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 103 150 return( 0 ); 104 151 } … … 106 153 static void sighandler( int signal ) 107 154 { 108 /* FIXME: In fact, calling log_message() here can be dangerous. But well, let's take the risk for now.*/155 /* FIXME: Calling log_message() here is not a very good idea! */ 109 156 110 157 if( signal == SIGTERM ) … … 132 179 } 133 180 } 181 else if( signal == SIGCHLD ) 182 { 183 pid_t pid; 184 int st; 185 186 while( ( pid = waitpid( 0, &st, WNOHANG ) ) > 0 ) 187 { 188 if( WIFSIGNALED( st ) ) 189 log_message( LOGLVL_INFO, "Client %d terminated normally. (status = %d)", pid, WEXITSTATUS( st ) ); 190 else if( WIFEXITED( st ) ) 191 log_message( LOGLVL_INFO, "Client %d killed by signal %d.", pid, WTERMSIG( st ) ); 192 } 193 } 134 194 else if( signal != SIGPIPE ) 135 195 {
Note: See TracChangeset
for help on using the changeset viewer.