1
0
mirror of https://github.com/osmarks/ngircd.git synced 2024-10-28 04:46:17 +00:00

Write "error file" (/tmp/ngircd-XXX.err) only if compiled with debug

code ("--enable-debug") and running as daemon process.
This commit is contained in:
Alexander Barton 2005-02-10 12:49:04 +00:00
parent 0993ff81bb
commit 9537542647
4 changed files with 69 additions and 21 deletions

View File

@ -12,6 +12,8 @@
ngIRCd CVSHEAD ngIRCd CVSHEAD
- Write "error file" (/tmp/ngircd-XXX.err) only if compiled with debug
code ("--enable-debug") and running as daemon process.
- Don't create version information string each time a client connects - Don't create version information string each time a client connects
but insetead on server startup. By Florian Westphal. but insetead on server startup. By Florian Westphal.
- New configuration variable "PidFile", section "[Global]": if defined, - New configuration variable "PidFile", section "[Global]": if defined,
@ -584,4 +586,4 @@ ngIRCd 0.0.1, 31.12.2001
-- --
$Id: ChangeLog,v 1.260 2005/02/09 09:52:58 alex Exp $ $Id: ChangeLog,v 1.261 2005/02/10 12:49:04 alex Exp $

View File

@ -14,7 +14,7 @@
#include "portab.h" #include "portab.h"
static char UNUSED id[] = "$Id: log.c,v 1.51 2005/02/09 09:52:58 alex Exp $"; static char UNUSED id[] = "$Id: log.c,v 1.52 2005/02/10 12:49:04 alex Exp $";
#include "imp.h" #include "imp.h"
#include <assert.h> #include <assert.h>
@ -44,9 +44,12 @@ static char UNUSED id[] = "$Id: log.c,v 1.51 2005/02/09 09:52:58 alex Exp $";
#include "log.h" #include "log.h"
LOCAL CHAR Error_File[FNAME_LEN];
LOCAL CHAR Init_Txt[127]; LOCAL CHAR Init_Txt[127];
#ifdef DEBUG
LOCAL CHAR Error_File[FNAME_LEN];
#endif
LOCAL VOID Wall_ServerNotice PARAMS(( CHAR *Msg )); LOCAL VOID Wall_ServerNotice PARAMS(( CHAR *Msg ));
@ -89,10 +92,14 @@ Log_Init( VOID )
#endif #endif
if( Init_Txt[0] ) Log( LOG_INFO, "Activating: %s.", Init_Txt ); if( Init_Txt[0] ) Log( LOG_INFO, "Activating: %s.", Init_Txt );
#ifdef DEBUG
Error_File[0] = '\0'; Error_File[0] = '\0';
#endif
} /* Log_Init */ } /* Log_Init */
#ifdef DEBUG
GLOBAL VOID GLOBAL VOID
Log_InitErrorfile( VOID ) Log_InitErrorfile( VOID )
{ {
@ -119,6 +126,8 @@ Log_InitErrorfile( VOID )
Log( LOG_DEBUG, "Redirected stderr to \"%s\".", Error_File ); Log( LOG_DEBUG, "Redirected stderr to \"%s\".", Error_File );
} /* Log_InitErrfile */ } /* Log_InitErrfile */
#endif
GLOBAL VOID GLOBAL VOID
Log_Exit( VOID ) Log_Exit( VOID )
@ -127,11 +136,13 @@ Log_Exit( VOID )
if( NGIRCd_SignalRestart ) Log( LOG_NOTICE, "%s done (restarting).", PACKAGE_NAME ); if( NGIRCd_SignalRestart ) Log( LOG_NOTICE, "%s done (restarting).", PACKAGE_NAME );
else Log( LOG_NOTICE, "%s done.", PACKAGE_NAME ); else Log( LOG_NOTICE, "%s done.", PACKAGE_NAME );
#ifdef DEBUG
if( Error_File[0] ) if( Error_File[0] )
{ {
/* Error-File (stderr) loeschen */ /* Error-File (stderr) loeschen */
if( unlink( Error_File ) != 0 ) Log( LOG_ERR, "Can't delete \"%s\": %s", Error_File, strerror( errno )); if( unlink( Error_File ) != 0 ) Log( LOG_ERR, "Can't delete \"%s\": %s", Error_File, strerror( errno ));
} }
#endif
#ifdef SYSLOG #ifdef SYSLOG
/* syslog abmelden */ /* syslog abmelden */
@ -198,7 +209,7 @@ va_dcl
if( Level <= LOG_CRIT ) if( Level <= LOG_CRIT )
{ {
/* Kritische Meldungen in Error-File (stderr) */ /* log critical messages to stderr */
fprintf( stderr, "%s\n", msg ); fprintf( stderr, "%s\n", msg );
fflush( stderr ); fflush( stderr );
} }

View File

@ -8,7 +8,7 @@
* (at your option) any later version. * (at your option) any later version.
* Please read the file COPYING, README and AUTHORS for more information. * Please read the file COPYING, README and AUTHORS for more information.
* *
* $Id: log.h,v 1.14 2003/12/26 15:55:07 alex Exp $ * $Id: log.h,v 1.15 2005/02/10 12:49:04 alex Exp $
* *
* Logging functions (header) * Logging functions (header)
*/ */
@ -38,7 +38,6 @@
GLOBAL VOID Log_Init PARAMS((VOID )); GLOBAL VOID Log_Init PARAMS((VOID ));
GLOBAL VOID Log_Exit PARAMS((VOID )); GLOBAL VOID Log_Exit PARAMS((VOID ));
GLOBAL VOID Log_InitErrorfile PARAMS((VOID ));
GLOBAL VOID Log PARAMS((INT Level, CONST CHAR *Format, ... )); GLOBAL VOID Log PARAMS((INT Level, CONST CHAR *Format, ... ));
GLOBAL VOID Log_Init_Resolver PARAMS((VOID )); GLOBAL VOID Log_Init_Resolver PARAMS((VOID ));
@ -46,6 +45,10 @@ GLOBAL VOID Log_Exit_Resolver PARAMS((VOID ));
GLOBAL VOID Log_Resolver PARAMS((CONST INT Level, CONST CHAR *Format, ... )); GLOBAL VOID Log_Resolver PARAMS((CONST INT Level, CONST CHAR *Format, ... ));
#ifdef DEBUG
GLOBAL VOID Log_InitErrorfile PARAMS((VOID ));
#endif
#endif #endif

View File

@ -14,7 +14,7 @@
#include "portab.h" #include "portab.h"
static char UNUSED id[] = "$Id: ngircd.c,v 1.90 2005/02/09 09:52:58 alex Exp $"; static char UNUSED id[] = "$Id: ngircd.c,v 1.91 2005/02/10 12:49:04 alex Exp $";
#include "imp.h" #include "imp.h"
#include <assert.h> #include <assert.h>
@ -28,6 +28,7 @@ static char UNUSED id[] = "$Id: ngircd.c,v 1.90 2005/02/09 09:52:58 alex Exp $";
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <fcntl.h>
#include <pwd.h> #include <pwd.h>
#include <grp.h> #include <grp.h>
@ -62,6 +63,8 @@ LOCAL VOID Pidfile_Delete PARAMS(( VOID ));
LOCAL VOID NGIRCd_FillVersion PARAMS(( VOID )); LOCAL VOID NGIRCd_FillVersion PARAMS(( VOID ));
LOCAL VOID Setup_FDStreams PARAMS(( VOID ));
GLOBAL int GLOBAL int
main( int argc, const char *argv[] ) main( int argc, const char *argv[] )
@ -267,29 +270,31 @@ main( int argc, const char *argv[] )
if( setuid( Conf_UID ) != 0 ) Log( LOG_ERR, "Can't change user ID to %u: %s", Conf_UID, strerror( errno )); if( setuid( Conf_UID ) != 0 ) Log( LOG_ERR, "Can't change user ID to %u: %s", Conf_UID, strerror( errno ));
} }
/* In der Regel wird ein Sub-Prozess ge-fork()'t, der /* Normally a child process is forked which isn't any longer
* nicht mehr mit dem Terminal verbunden ist. Mit der * connected to ther controlling terminal. Use "--nodaemon"
* Option "--nodaemon" kann dies (z.B. zum Debuggen) * to disable this "daemon mode" (useful for debugging). */
* verhindert werden. */
if( ! NGIRCd_NoDaemon ) if( ! NGIRCd_NoDaemon )
{ {
/* Daemon im Hintergrund erzeugen */ /* fork child process */
pid = (LONG)fork( ); pid = (LONG)fork( );
if( pid > 0 ) if( pid > 0 )
{ {
/* "alter" Prozess */ /* "Old" process: exit. */
exit( 0 ); exit( 0 );
} }
if( pid < 0 ) if( pid < 0 )
{ {
/* Fehler */ /* Error!? */
printf( "%s: Can't fork: %s!\nFatal error, exiting now ...\n", PACKAGE_NAME, strerror( errno )); fprintf( stderr, "%s: Can't fork: %s!\nFatal error, exiting now ...\n", PACKAGE_NAME, strerror( errno ));
exit( 1 ); exit( 1 );
} }
/* Child-Prozess initialisieren */ /* New child process */
(VOID)setsid( ); (VOID)setsid( );
chdir( "/" ); chdir( "/" );
/* Detach stdin, stdout and stderr */
(VOID)Setup_FDStreams( );
} }
/* Create PID file */ /* Create PID file */
@ -326,11 +331,11 @@ main( int argc, const char *argv[] )
#endif #endif
Conn_Init( ); Conn_Init( );
/* Redirect stderr handle to "error file" for debugging. #ifdef DEBUG
* But don't try to write in the chroot jail, since it's more /* Redirect stderr handle to "error file" for debugging
* secure to have a chroot dir not writable by the daemon. * when not running in "no daemon" mode: */
*/ if( ! NGIRCd_NoDaemon ) Log_InitErrorfile( );
if( ! Conf_Chroot[0] ) Log_InitErrorfile( ); #endif
/* Signal-Handler initialisieren */ /* Signal-Handler initialisieren */
Initialize_Signal_Handler( ); Initialize_Signal_Handler( );
@ -629,4 +634,31 @@ Pidfile_Create( LONG pid )
} /* Pidfile_Create */ } /* Pidfile_Create */
LOCAL VOID
Setup_FDStreams( VOID )
{
int fd;
/* Test if we can open /dev/null for reading and writing. If not
* we are most probably chrooted already and the server has been
* restarted. So we simply don't try to redirect stdXXX ... */
fd = open( "/dev/null", O_RDWR );
if ( fd < 0 ) return;
/* Close "old" stdin/out/err descriptors */
fclose( stdin ); fclose( stdout ); fclose( stderr );
/* Create new stdin(0), stdout(1) and stderr(2) descriptors */
dup2( fd, 0 ); dup2( fd, 1 ); dup2( fd, 2 );
/* Close newly opened file descriptor if not stdin/out/err */
if( fd > 2 ) close( fd );
/* Assign FILE handles for stdin/out/err */
stdin = fdopen( 0, "r" );
stdout = fdopen( 1, "w" );
stderr = fdopen( 2, "w" );
} /* Setup_FDStreams */
/* -eof- */ /* -eof- */