aboutsummaryrefslogtreecommitdiffstats
path: root/unix.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2005-12-26 15:02:47 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2005-12-26 15:02:47 +0100
commitd25f6fcbe8e291dd858bf734fa85cde176dc8415 (patch)
tree58fffb8b1dd8cc0a3cf3583c0daf7c10271af871 /unix.c
parentffea9b950b183dd54952b56703506508b0984d4b (diff)
Added OperPassword and RunMode = ForkDaemon settings. Oper stuff is
*INSECURE* because users can just do /mode +o to become operator.
Diffstat (limited to 'unix.c')
-rw-r--r--unix.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/unix.c b/unix.c
index a1f39753..fafa828e 100644
--- a/unix.c
+++ b/unix.c
@@ -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();
@@ -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 );