diff options
| author | Wilmer van der Gaast <wilmer@gaast.net> | 2006-02-02 14:21:44 +0100 | 
|---|---|---|
| committer | Wilmer van der Gaast <wilmer@gaast.net> | 2006-02-02 14:21:44 +0100 | 
| commit | 34b17d9b8901b72439167b99d780c481ce420e33 (patch) | |
| tree | d04b9d40c66b16c170966df19e3f58c7c778e26d | |
| parent | 8365610bb2013d3478214511910daceabd29ad09 (diff) | |
Added PID-file code.
| -rw-r--r-- | bitlbee.c | 11 | ||||
| -rw-r--r-- | conf.c | 13 | ||||
| -rw-r--r-- | conf.h | 1 | ||||
| -rwxr-xr-x | configure | 5 | 
4 files changed, 29 insertions, 1 deletions
@@ -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 );  } @@ -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 ); @@ -42,6 +42,7 @@ typedef struct conf  	char *hostname;  	char *configdir;  	char *plugindir; +	char *pidfile;  	char *motdfile;  	char *primary_storage;  	char **migrate_storage; @@ -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  | 
