New configuration variable "PidFile", section "[Global]": if defined,

the server writes its process ID (PID) to this file. Default: off.
Idea by Florian Westphal, <westphal@foo.fh-furtwangen.de>.
This commit is contained in:
Alexander Barton 2005-02-04 14:24:20 +00:00
parent ae63ed04c5
commit 112102b10c
7 changed files with 93 additions and 11 deletions

View File

@ -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 $

7
NEWS
View File

@ -12,9 +12,12 @@
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 $

View 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
@ -67,6 +67,12 @@
# 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

View 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 */

View 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;

View 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"

View 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- */