]> arthur.barton.de Git - ngircd-alex.git/commitdiff
New configuration variable "PidFile", section "[Global]": if defined,
authorAlexander Barton <alex@barton.de>
Fri, 4 Feb 2005 14:24:20 +0000 (14:24 +0000)
committerAlexander Barton <alex@barton.de>
Fri, 4 Feb 2005 14:24:20 +0000 (14:24 +0000)
the server writes its process ID (PID) to this file. Default: off.
Idea by Florian Westphal, <westphal@foo.fh-furtwangen.de>.

ChangeLog
NEWS
doc/sample-ngircd.conf
src/ngircd/conf.c
src/ngircd/conf.h
src/ngircd/defines.h
src/ngircd/ngircd.c

index ee91f31c0add2912ba0d329f0e35ba163843ce5b..b5d799d5717b95f7b0b2032adce5f0258ed22e4f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,6 +12,9 @@
 
 ngIRCd CVSHEAD
 
+  - New configuration variable "PidFile", section "[Global]": if defined,
+    the server writes its process ID (PID) to this file. Default: off.
+    Idea of Florian Westphal, <westphal@foo.fh-furtwangen.de>.
   - Code cleanups from Florian Westphal, <westphal@foo.fh-furtwangen.de>.
   - Raised the maximum length of passwords to 20 characters.
   - Fixed a memory leak when resizing the connection pool and realloc()
@@ -19,7 +22,7 @@ ngIRCd CVSHEAD
     Patch from Florian Westphal, <westphal@foo.fh-furtwangen.de>.
   - Added support for the Howl (http://www.porchdogsoft.com/products/howl/)
     Rendezvous API, in addition to the API of Apple (Mac OS X). The available
-    APU will be autodetected when you call "./configure --with-rendezvous".
+    API will be autodetected when you call "./configure --with-rendezvous".
   - Made ngIRCd compile on HP/UX 10.20 with native HP pre-ANSI C compiler and
     most probably other older C compilers on other systems.
   - When the daemon should switch to another user ID (ServerID is defined in
@@ -579,4 +582,4 @@ ngIRCd 0.0.1, 31.12.2001
 
 
 -- 
-$Id: ChangeLog,v 1.258 2005/02/04 14:21:35 alex Exp $
+$Id: ChangeLog,v 1.259 2005/02/04 14:24:20 alex Exp $
diff --git a/NEWS b/NEWS
index 09b9a62f2ccd4d3a07c7f97943f7d824a32adc93..9b1efedfd95c0c36bcead3d62faeaced96e0b5fe 100644 (file)
--- a/NEWS
+++ b/NEWS
 
 ngIRCd CVSHEAD
 
+  - New configuration variable "PidFile", section "[Global]": if defined,
+    the server writes its process ID (PID) to this file. Default: off.
+    Idea of Florian Westphal, <westphal@foo.fh-furtwangen.de>.
   - Added support for the Howl (http://www.porchdogsoft.com/products/howl/)
     Rendezvous API, in addition to the API of Apple (Mac OS X). The available
-    APU will be autodetected when you call "./configure --with-rendezvous".
+    API will be autodetected when you call "./configure --with-rendezvous".
 
 ngIRCd 0.8.0 (2004-06-26)
 
@@ -195,4 +198,4 @@ ngIRCd 0.0.1, 31.12.2001
 
 
 -- 
-$Id: NEWS,v 1.67 2004/12/26 00:14:33 alex Exp $
+$Id: NEWS,v 1.68 2005/02/04 14:24:20 alex Exp $
index d872b0de91152c0028f83cb0532c298405815aae..a34f04801ed84b6c6a071a86d6811fe66293660e 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: sample-ngircd.conf,v 1.29 2005/01/17 12:51:17 alex Exp $
+# $Id: sample-ngircd.conf,v 1.30 2005/02/04 14:24:21 alex Exp $
 
 #
 # This is a sample configuration file for the ngIRCd, which must be adepted
        # with root privileges!
        ;ChrootDir = /var/empty
 
+       # This tells ngircd to write its current process id to a file.
+       # Note that the pidfile is written AFTER chroot and switching uid, i.e.
+       # the Directory the pidfile resides in must be writeable by the ngircd user and
+       # exist in the chroot dir.
+       ;PidFile = /var/run/ngircd/ngircd.pid
+
        # After <PingTimeout> seconds of inactivity the server will send a
        # PING to the peer to test whether it is alive or not.
        ;PingTimeout = 120
index d1696b921afe3c57a20c1efd545e68a482962787..17090d8a5e4af5df85077d1274b4c91b33ca9fae 100644 (file)
@@ -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 */
index 4fbf2d68597c4d8a69f990d5244570ff69d11104..93c8ebf0d241b320902281c355188f0ea0489cba 100644 (file)
@@ -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;
index 1b7a1d0d02b79970f8b3a995804c69b7c4195b6d..12558ef37589a82a4db5d2eb28044d31b0c9367d 100644 (file)
@@ -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"
 
index 52019a76d4c18e038c42c2698f2bf39eabd0d0da..89b2f7f8b0362406c0bbb2909bb77a52bc389f4a 100644 (file)
@@ -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- */