From a49dcd5c3c6b79470ad71dc45ccf29f65ba2a7f9 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 22 Jan 2006 21:33:56 +0100 Subject: Fixed the bug that caused a fork() bomb last night. --- bitlbee.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bitlbee.c b/bitlbee.c index 5da5d6e1..2f757f53 100644 --- a/bitlbee.c +++ b/bitlbee.c @@ -103,10 +103,14 @@ int bitlbee_daemon_init() } else if( i != 0 ) exit( 0 ); - close( 0 ); - close( 1 ); - close( 2 ); + chdir( "/" ); + + /* Sometimes std* are already closed (for example when we're in a RESTARTed + BitlBee process. So let's only close TTY-fds. */ + if( isatty( 0 ) ) close( 0 ); + if( isatty( 0 ) ) close( 1 ); + if( isatty( 0 ) ) close( 2 ); } #endif -- cgit v1.2.3 From 105383688a6605ca40ab4fa987d72809170a2e36 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Mon, 30 Jan 2006 14:30:59 +0100 Subject: When closing down MSN (sb) connections with unsent messages, the warning message now mentions the people those messages were meant for. --- protocols/msn/msn.c | 4 ++-- protocols/msn/sb.c | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index b03c898e..3c7064f8 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -83,13 +83,13 @@ static void msn_close( struct gaim_connection *gc ) for( l = md->msgq; l; l = l->next ) { m = l->data; + + serv_got_crap( gc, "Warning: Closing down MSN connection with unsent message to %s, you'll have to resend it.", m->who ); g_free( m->who ); g_free( m->text ); g_free( m ); } g_slist_free( md->msgq ); - - serv_got_crap( gc, "Warning: Closing down MSN connection with unsent message(s), you'll have to resend them." ); } for( l = gc->permit; l; l = l->next ) diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c index 9e7ef841..deaceba1 100644 --- a/protocols/msn/sb.c +++ b/protocols/msn/sb.c @@ -212,13 +212,16 @@ void msn_sb_destroy( struct msn_switchboard *sb ) for( l = sb->msgq; l; l = l->next ) { m = l->data; + g_free( m->who ); g_free( m->text ); g_free( m ); } g_slist_free( sb->msgq ); - serv_got_crap( gc, "Warning: Closing down MSN switchboard connection with unsent message(s), you'll have to resend them." ); + serv_got_crap( gc, "Warning: Closing down MSN switchboard connection with " + "unsent message to %s, you'll have to resend it.", + m->who ? m->who : "(unknown)" ); } if( sb->chat ) -- cgit v1.2.3 From 8365610bb2013d3478214511910daceabd29ad09 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Mon, 30 Jan 2006 17:07:07 +0100 Subject: Added a little warning message when people use a wrong set-command syntax. --- root_commands.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/root_commands.c b/root_commands.c index 426cf6e8..f69442d3 100644 --- a/root_commands.c +++ b/root_commands.c @@ -600,6 +600,9 @@ static void cmd_set( irc_t *irc, char **cmd ) if( cmd[1] && cmd[2] ) { set_setstr( irc, cmd[1], cmd[2] ); + + if( ( strcmp( cmd[2], "=" ) ) == 0 && cmd[3] ) + irc_usermsg( irc, "Warning: Correct syntax: \002set \002 (without =)" ); } if( cmd[1] ) /* else 'forgotten' on purpose.. Must show new value after changing */ { -- cgit v1.2.3 From 34b17d9b8901b72439167b99d780c481ce420e33 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 2 Feb 2006 14:21:44 +0100 Subject: Added PID-file code. --- bitlbee.c | 11 +++++++++++ conf.c | 13 ++++++++++++- conf.h | 1 + configure | 5 +++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/bitlbee.c b/bitlbee.c index 9a4688d8..ac7823a4 100644 --- a/bitlbee.c +++ b/bitlbee.c @@ -44,6 +44,7 @@ int bitlbee_daemon_init() #endif int i; GIOChannel *ch; + FILE *fp; log_link( LOGLVL_ERROR, LOGOUTPUT_SYSLOG ); log_link( LOGLVL_WARNING, LOGOUTPUT_SYSLOG ); @@ -110,6 +111,16 @@ int bitlbee_daemon_init() } #endif + if( ( fp = fopen( global.conf->pidfile, "w" ) ) ) + { + fprintf( fp, "%d\n", (int) getpid() ); + fclose( fp ); + } + else + { + log_message( LOGLVL_WARNING, "Warning: Couldn't write PID to `%s'", global.conf->pidfile ); + } + return( 0 ); } diff --git a/conf.c b/conf.c index ae4b77a2..d38b7a68 100644 --- a/conf.c +++ b/conf.c @@ -60,6 +60,7 @@ conf_t *conf_load( int argc, char *argv[] ) conf->oper_pass = NULL; conf->configdir = g_strdup( CONFIG ); conf->plugindir = g_strdup( PLUGINDIR ); + conf->pidfile = g_strdup( "/var/run/bitlbee.pid" ); conf->motdfile = g_strdup( ETCDIR "/motd.txt" ); conf->ping_interval = 180; conf->ping_timeout = 300; @@ -76,7 +77,7 @@ conf_t *conf_load( int argc, char *argv[] ) fprintf( stderr, "Warning: Unable to read configuration file `%s'.\n", CONF_FILE ); } - while( argc > 0 && ( opt = getopt( argc, argv, "i:p:nvIDFc:d:h" ) ) >= 0 ) + while( argc > 0 && ( opt = getopt( argc, argv, "i:p:P:nvIDFc:d:h" ) ) >= 0 ) /* ^^^^ Just to make sure we skip this step from the REHASH handler. */ { if( opt == 'i' ) @@ -92,6 +93,11 @@ conf_t *conf_load( int argc, char *argv[] ) } conf->port = i; } + else if( opt == 'p' ) + { + g_free( conf->pidfile ); + conf->pidfile = g_strdup( optarg ); + } else if( opt == 'n' ) conf->nofork = 1; else if( opt == 'v' ) @@ -175,6 +181,11 @@ static int conf_loadini( conf_t *conf, char *file ) else conf->runmode = RUNMODE_INETD; } + else if( g_strcasecmp( ini->key, "pidfile" ) == 0 ) + { + g_free( conf->pidfile ); + conf->pidfile = g_strdup( ini->value ); + } else if( g_strcasecmp( ini->key, "daemoninterface" ) == 0 ) { conf->iface = g_strdup( ini->value ); diff --git a/conf.h b/conf.h index d6460901..e852dbef 100644 --- a/conf.h +++ b/conf.h @@ -42,6 +42,7 @@ typedef struct conf char *hostname; char *configdir; char *plugindir; + char *pidfile; char *motdfile; char *primary_storage; char **migrate_storage; diff --git a/configure b/configure index 7900967b..2731d5b1 100755 --- a/configure +++ b/configure @@ -13,6 +13,7 @@ etcdir='$prefix/etc/bitlbee/' mandir='$prefix/share/man/' datadir='$prefix/share/bitlbee/' config='/var/lib/bitlbee/' +pidfile='/var/run/bitlbee.pid' plugindir='$prefix/lib/bitlbee' msn=1 @@ -45,6 +46,7 @@ Option Description Default --mandir=... $mandir --datadir=... $datadir --plugindir=... $plugindir +--pidfile=... $pidfile --config=... $config --msn=0/1 Disable/enable MSN part $msn @@ -73,6 +75,7 @@ mandir=`eval echo "$mandir/" | sed 's/\/\{1,\}/\//g'` datadir=`eval echo "$datadir/" | sed 's/\/\{1,\}/\//g'` config=`eval echo "$config/" | sed 's/\/\{1,\}/\//g'` plugindir=`eval echo "$plugindir/" | sed 's/\/\{1,\}/\//g'` +pidfile=`eval echo "$pidfile/" | sed 's/\/\{1,\}/\//g'` cat<Makefile.settings ## BitlBee settings, generated by configure @@ -82,6 +85,7 @@ ETCDIR=$etcdir MANDIR=$mandir DATADIR=$datadir PLUGINDIR=$plugindir +PIDFILE=$pidfile CONFIG=$config ARCH=$arch @@ -103,6 +107,7 @@ cat<config.h #define ETCDIR "$etcdir" #define VARDIR "$datadir" #define PLUGINDIR "$plugindir" +#define PIDFILE "$pidfile" #define ARCH "$arch" #define CPU "$cpu" EOF -- cgit v1.2.3