aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bitlbee.c11
-rw-r--r--conf.c13
-rw-r--r--conf.h1
-rwxr-xr-xconfigure5
4 files changed, 29 insertions, 1 deletions
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<<EOF>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<<EOF>config.h
#define ETCDIR "$etcdir"
#define VARDIR "$datadir"
#define PLUGINDIR "$plugindir"
+#define PIDFILE "$pidfile"
#define ARCH "$arch"
#define CPU "$cpu"
EOF