diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2006-01-10 22:35:08 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2006-01-10 22:35:08 +0100 |
commit | 8e419cb4f86679636b2d96618e1bec4853636c11 (patch) | |
tree | b7514f0bd06ce2a1f5290c53552c692698091d2b /unix.c | |
parent | 3e91c3ec7d6426c4c2819e78275f935e1a7fce2c (diff) | |
parent | dd8d4c5243eea91dd3b0709ae76abdd3743e99bc (diff) |
Merge Wilmer
Diffstat (limited to 'unix.c')
-rw-r--r-- | unix.c | 27 |
1 files changed, 23 insertions, 4 deletions
@@ -31,6 +31,7 @@ #include <signal.h> #include <unistd.h> #include <sys/time.h> +#include <sys/wait.h> global_t global; /* Against global namespace pollution */ @@ -45,7 +46,7 @@ int main( int argc, char *argv[] ) global.loop = g_main_new( FALSE ); - log_init( ); + log_init(); nogaim_init(); @@ -75,11 +76,15 @@ int main( int argc, char *argv[] ) i = bitlbee_daemon_init(); log_message( LOGLVL_INFO, "Bitlbee %s starting in daemon mode.", BITLBEE_VERSION ); } + else if( global.conf->runmode == RUNMODE_FORKDAEMON ) + { + i = bitlbee_daemon_init(); + log_message( LOGLVL_INFO, "Bitlbee %s starting in forking daemon mode.", BITLBEE_VERSION ); + } if( i != 0 ) return( i ); - global.storage = storage_init( global.conf->primary_storage, - global.conf->migrate_storage ); + global.storage = storage_init( global.conf->primary_storage, global.conf->migrate_storage ); if ( global.storage == NULL) { log_message( LOGLVL_ERROR, "Unable to load storage backend '%s'", global.conf->primary_storage ); return( 1 ); @@ -89,6 +94,7 @@ int main( int argc, char *argv[] ) /* Catch some signals to tell the user what's happening before quitting */ memset( &sig, 0, sizeof( sig ) ); sig.sa_handler = sighandler; + sigaction( SIGCHLD, &sig, &old ); sigaction( SIGPIPE, &sig, &old ); sig.sa_flags = SA_RESETHAND; sigaction( SIGINT, &sig, &old ); @@ -112,7 +118,7 @@ int main( int argc, char *argv[] ) static void sighandler( int signal ) { - /* FIXME: In fact, calling log_message() here can be dangerous. But well, let's take the risk for now. */ + /* FIXME: Calling log_message() here is not a very good idea! */ if( signal == SIGTERM ) { @@ -138,6 +144,19 @@ static void sighandler( int signal ) raise( signal ); } } + else if( signal == SIGCHLD ) + { + pid_t pid; + int st; + + while( ( pid = waitpid( 0, &st, WNOHANG ) ) > 0 ) + { + if( WIFSIGNALED( st ) ) + log_message( LOGLVL_INFO, "Client %d terminated normally. (status = %d)", pid, WEXITSTATUS( st ) ); + else if( WIFEXITED( st ) ) + log_message( LOGLVL_INFO, "Client %d killed by signal %d.", pid, WTERMSIG( st ) ); + } + } else if( signal != SIGPIPE ) { log_message( LOGLVL_ERROR, "Fatal signal received: %d. That's probably a bug.", signal ); |