commit - 0993ff81bb54fe45e4c2feacdab9ea8d2da5b60b
commit + 9537542647b014894227de81a59fb063fc0dc3e4
blob - 7694623b7aa4d3c0c5b9689002c7ae953156bc01
blob + 7d134b6fcbce5fd7eb3fc8c5c86ba74f5de78a45
--- ChangeLog
+++ ChangeLog
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
but insetead on server startup. By Florian Westphal.
- New configuration variable "PidFile", section "[Global]": if defined,
--
-$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 $
blob - 01821829c1b023a68a368c5017aebb43e0c2f1e9
blob + 153ffedd9c48fa238e49ca5f34b4bd896b9c1fbd
--- src/ngircd/log.c
+++ src/ngircd/log.c
#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 <assert.h>
#include "log.h"
-LOCAL CHAR Error_File[FNAME_LEN];
LOCAL CHAR Init_Txt[127];
+#ifdef DEBUG
+LOCAL CHAR Error_File[FNAME_LEN];
+#endif
+
LOCAL VOID Wall_ServerNotice PARAMS(( CHAR *Msg ));
#endif
if( Init_Txt[0] ) Log( LOG_INFO, "Activating: %s.", Init_Txt );
+#ifdef DEBUG
Error_File[0] = '\0';
+#endif
} /* Log_Init */
+#ifdef DEBUG
+
GLOBAL VOID
Log_InitErrorfile( VOID )
{
Log( LOG_DEBUG, "Redirected stderr to \"%s\".", Error_File );
} /* Log_InitErrfile */
+#endif
+
GLOBAL VOID
Log_Exit( VOID )
{
if( NGIRCd_SignalRestart ) Log( LOG_NOTICE, "%s done (restarting).", PACKAGE_NAME );
else Log( LOG_NOTICE, "%s done.", PACKAGE_NAME );
+#ifdef DEBUG
if( Error_File[0] )
{
/* Error-File (stderr) loeschen */
if( unlink( Error_File ) != 0 ) Log( LOG_ERR, "Can't delete \"%s\": %s", Error_File, strerror( errno ));
}
+#endif
#ifdef SYSLOG
/* syslog abmelden */
if( Level <= LOG_CRIT )
{
- /* Kritische Meldungen in Error-File (stderr) */
+ /* log critical messages to stderr */
fprintf( stderr, "%s\n", msg );
fflush( stderr );
}
blob - 028985c44cd7ec19e4bb14e09736b3bd78e79bfc
blob + 24c3f88cfdff3b2124952587f1859e873de4905a
--- src/ngircd/log.h
+++ src/ngircd/log.h
* (at your option) any later version.
* 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)
*/
GLOBAL VOID Log_Init 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_Init_Resolver PARAMS((VOID ));
GLOBAL VOID Log_Resolver PARAMS((CONST INT Level, CONST CHAR *Format, ... ));
+#ifdef DEBUG
+GLOBAL VOID Log_InitErrorfile PARAMS((VOID ));
+#endif
+
#endif
blob - 191c216a1ac0df60fe38362338328c82e6500250
blob + e39229a06d97e252c61515d74fce8c3e16abeb6f
--- src/ngircd/ngircd.c
+++ src/ngircd/ngircd.c
#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 <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
+#include <fcntl.h>
#include <pwd.h>
#include <grp.h>
LOCAL VOID Pidfile_Delete PARAMS(( VOID ));
LOCAL VOID NGIRCd_FillVersion PARAMS(( VOID ));
+
+LOCAL VOID Setup_FDStreams PARAMS(( VOID ));
GLOBAL int
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
- * nicht mehr mit dem Terminal verbunden ist. Mit der
- * Option "--nodaemon" kann dies (z.B. zum Debuggen)
- * verhindert werden. */
+ /* Normally a child process is forked which isn't any longer
+ * connected to ther controlling terminal. Use "--nodaemon"
+ * to disable this "daemon mode" (useful for debugging). */
if( ! NGIRCd_NoDaemon )
{
- /* Daemon im Hintergrund erzeugen */
+ /* fork child process */
pid = (LONG)fork( );
if( pid > 0 )
{
- /* "alter" Prozess */
+ /* "Old" process: exit. */
exit( 0 );
}
if( pid < 0 )
{
- /* Fehler */
- printf( "%s: Can't fork: %s!\nFatal error, exiting now ...\n", PACKAGE_NAME, strerror( errno ));
+ /* Error!? */
+ fprintf( stderr, "%s: Can't fork: %s!\nFatal error, exiting now ...\n", PACKAGE_NAME, strerror( errno ));
exit( 1 );
}
- /* Child-Prozess initialisieren */
+ /* New child process */
(VOID)setsid( );
chdir( "/" );
+
+ /* Detach stdin, stdout and stderr */
+ (VOID)Setup_FDStreams( );
}
/* Create PID file */
#endif
Conn_Init( );
- /* Redirect stderr handle to "error file" for debugging.
- * But don't try to write in the chroot jail, since it's more
- * secure to have a chroot dir not writable by the daemon.
- */
- if( ! Conf_Chroot[0] ) Log_InitErrorfile( );
+#ifdef DEBUG
+ /* Redirect stderr handle to "error file" for debugging
+ * when not running in "no daemon" mode: */
+ if( ! NGIRCd_NoDaemon ) Log_InitErrorfile( );
+#endif
/* Signal-Handler initialisieren */
Initialize_Signal_Handler( );
if( fclose(pidf) != 0 )
Log( LOG_ERR, "Error closing PID file (%s): %s", Conf_PidFile, strerror( errno ));
} /* 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- */