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