From d25f6fcbe8e291dd858bf734fa85cde176dc8415 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Mon, 26 Dec 2005 15:02:47 +0100 Subject: Added OperPassword and RunMode = ForkDaemon settings. Oper stuff is *INSECURE* because users can just do /mode +o to become operator. --- unix.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'unix.c') diff --git a/unix.c b/unix.c index a1f39753..fafa828e 100644 --- a/unix.c +++ b/unix.c @@ -31,6 +31,7 @@ #include #include #include +#include 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(); @@ -69,11 +70,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 ); @@ -83,6 +88,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 ); @@ -106,7 +112,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 ) { @@ -132,6 +138,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 ); -- cgit v1.2.3