about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ngircd/conf.c17
-rw-r--r--src/ngircd/conf.h5
-rw-r--r--src/ngircd/defines.h3
-rw-r--r--src/ngircd/ngircd.c57
4 files changed, 76 insertions, 6 deletions
diff --git a/src/ngircd/conf.c b/src/ngircd/conf.c
index d1696b92..17090d8a 100644
--- a/src/ngircd/conf.c
+++ b/src/ngircd/conf.c
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: conf.c,v 1.67 2005/01/20 00:13:08 alex Exp $";
+static char UNUSED id[] = "$Id: conf.c,v 1.68 2005/02/04 14:24:21 alex Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -122,7 +122,8 @@ Conf_Test( VOID )
 	printf( "  AdminEMail = %s\n", Conf_ServerAdminMail );
 	printf( "  MotdFile = %s\n", Conf_MotdFile );
 	printf( "  MotdPhrase = %s\n", Conf_MotdPhrase );
-	printf( "  ChrootDir= %s\n", Conf_Chroot );
+	printf( "  ChrootDir = %s\n", Conf_Chroot );
+	printf( "  PidFile = %s\n", Conf_PidFile);
 	printf( "  Ports = " );
 	for( i = 0; i < Conf_ListenPorts_Count; i++ )
 	{
@@ -356,6 +357,8 @@ Set_Defaults( BOOLEAN InitServers )
 
 	strlcpy( Conf_Chroot, CHROOT_DIR, sizeof( Conf_Chroot ));
 
+	strlcpy( Conf_PidFile, PID_FILE, sizeof( Conf_PidFile ));
+
 	Conf_ListenPorts_Count = 0;
 	strcpy( Conf_ListenAddress, "" );
 
@@ -650,6 +653,16 @@ Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg )
 
 		return;
 	}
+
+	if ( strcasecmp( Var, "PidFile" ) == 0 )
+	{
+		/* name of pidfile */
+		if( strlcpy( Conf_PidFile, Arg, sizeof( Conf_PidFile )) >= sizeof( Conf_PidFile ))
+			Config_Error_TooLong( Line, Var );
+
+		return;
+	}
+
 	if( strcasecmp( Var, "ServerUID" ) == 0 )
 	{
 		/* UID the daemon should switch to */
diff --git a/src/ngircd/conf.h b/src/ngircd/conf.h
index 4fbf2d68..93c8ebf0 100644
--- a/src/ngircd/conf.h
+++ b/src/ngircd/conf.h
@@ -8,7 +8,7 @@
  * (at your option) any later version.
  * Please read the file COPYING, README and AUTHORS for more information.
  *
- * $Id: conf.h,v 1.29 2004/05/07 11:19:21 alex Exp $
+ * $Id: conf.h,v 1.30 2005/02/04 14:24:21 alex Exp $
  *
  * Configuration management (header)
  */
@@ -89,6 +89,9 @@ GLOBAL UINT Conf_GID;
 /* A directory to chroot() in */
 GLOBAL CHAR Conf_Chroot[FNAME_LEN];
 
+/* File with PID of daemon */
+GLOBAL CHAR Conf_PidFile[FNAME_LEN];
+
 /* Timeouts for PING and PONG */
 GLOBAL INT Conf_PingTimeout;
 GLOBAL INT Conf_PongTimeout;
diff --git a/src/ngircd/defines.h b/src/ngircd/defines.h
index 1b7a1d0d..12558ef3 100644
--- a/src/ngircd/defines.h
+++ b/src/ngircd/defines.h
@@ -8,7 +8,7 @@
  * (at your option) any later version.
  * Please read the file COPYING, README and AUTHORS for more information.
  *
- * $Id: defines.h,v 1.48 2005/01/17 13:14:36 alex Exp $
+ * $Id: defines.h,v 1.49 2005/02/04 14:24:21 alex Exp $
  *
  * Global defines of ngIRCd.
  */
@@ -85,6 +85,7 @@
 #define MOTD_FILE "/ngircd.motd"
 #define MOTD_PHRASE ""
 #define CHROOT_DIR ""
+#define PID_FILE ""
 
 #define ERROR_DIR "/tmp"
 
diff --git a/src/ngircd/ngircd.c b/src/ngircd/ngircd.c
index 52019a76..89b2f7f8 100644
--- a/src/ngircd/ngircd.c
+++ b/src/ngircd/ngircd.c
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: ngircd.c,v 1.87 2005/01/26 22:03:15 alex Exp $";
+static char UNUSED id[] = "$Id: ngircd.c,v 1.88 2005/02/04 14:24:21 alex Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -57,6 +57,9 @@ LOCAL VOID Signal_Handler PARAMS(( INT Signal ));
 LOCAL VOID Show_Version PARAMS(( VOID ));
 LOCAL VOID Show_Help PARAMS(( VOID ));
 
+LOCAL VOID Pidfile_Create PARAMS(( LONG ));
+LOCAL VOID Pidfile_Delete PARAMS(( VOID ));
+
 
 GLOBAL int
 main( int argc, const char *argv[] )
@@ -285,9 +288,13 @@ main( int argc, const char *argv[] )
 			chdir( "/" );
 		}
 
+		/* Create PID file */
+		pid = (LONG) getpid( );
+		Pidfile_Create( pid );
+
 		/* Show user, group, and PID of the running daemon */
 		pwd = getpwuid( getuid( )); grp = getgrgid( getgid( ));
-		Log( LOG_INFO, "Running as user %s(%ld), group %s(%ld), with PID %ld.", pwd ? pwd->pw_name : "unknown", (LONG)getuid( ), grp ? grp->gr_name : "unknown", (LONG)getgid( ), (LONG)getpid( ));
+		Log( LOG_INFO, "Running as user %s(%ld), group %s(%ld), with PID %ld.", pwd ? pwd->pw_name : "unknown", (LONG)getuid( ), grp ? grp->gr_name : "unknown", (LONG)getgid( ), pid);
 
 		/* Change working directory to home directory of the user
 		 * we are running as (when not running chroot()'ed!) */
@@ -350,6 +357,7 @@ main( int argc, const char *argv[] )
 		{
 			Log( LOG_ALERT, "Server isn't listening on a single port!" );
 			Log( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
+			Pidfile_Delete( );
 			exit( 1 );
 		}
 		
@@ -365,6 +373,8 @@ main( int argc, const char *argv[] )
 		Channel_Exit( );
 		Lists_Exit( );
 		Log_Exit( );
+
+		Pidfile_Delete( );
 	}
 
 	return 0;
@@ -585,4 +595,47 @@ Show_Help( VOID )
 } /* Show_Help */
 
 
+LOCAL VOID
+Pidfile_Delete( VOID )
+{
+	/* Pidfile configured? */
+	if( ! Conf_PidFile[0] ) return;
+
+#ifdef DEBUG
+	Log( LOG_DEBUG, "Removing PID file (%s) ...", Conf_PidFile );
+#endif
+
+	if( unlink( Conf_PidFile ))
+		Log( LOG_ERR, "Error unlinking PID file (%s): %s", Conf_PidFile, strerror( errno ));
+} /* Pidfile_Delete */
+
+
+LOCAL VOID
+Pidfile_Create( LONG pid )
+{
+	FILE *pidf;
+
+	/* Pidfile configured? */
+	if( ! Conf_PidFile[0] ) return;
+
+	pidf = fopen( Conf_PidFile, "w" );
+
+#ifdef DEBUG
+	Log( LOG_DEBUG, "Creating PID file (%s) ...", Conf_PidFile );
+#endif
+
+	if( ! pidf )
+	{
+		Log( LOG_ERR, "Error writing PID file (%s): %s", Conf_PidFile, strerror( errno ));
+		return;
+	}
+
+	if( fprintf( pidf, "%ld\n", pid ) < 0 )
+		Log( LOG_ERR, "Can't write PID file (%s): %s", Conf_PidFile, strerror( errno ));
+
+	if( fclose(pidf) != 0 )
+		Log( LOG_ERR, "Error closing PID file (%s): %s", Conf_PidFile, strerror( errno ));
+} /* Pidfile_Create */
+
+
 /* -eof- */