X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Flog.c;h=0ea5986d693cfe63db460d0a33ef5df7a8098132;hp=394817b0277de1a070141cb84f88b0657888975e;hb=3d74a9c323fa99dbcba47a1c3978ef4984530f92;hpb=ca33cbda05902b0009058d369f88c0a7a43b1bbe diff --git a/src/ngircd/log.c b/src/ngircd/log.c index 394817b0..0ea5986d 100644 --- a/src/ngircd/log.c +++ b/src/ngircd/log.c @@ -9,15 +9,12 @@ * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS. * - * $Id: log.c,v 1.21 2002/03/12 14:37:52 alex Exp $ + * $Id: log.c,v 1.29 2002/03/29 23:33:42 alex Exp $ * * log.c: Logging-Funktionen */ -#define MAX_LOG_MSG_LEN 256 - - #include "portab.h" #include "imp.h" @@ -34,16 +31,23 @@ #endif #include "ngircd.h" +#include "client.h" #include "defines.h" +#include "irc-write.h" #include "exp.h" #include "log.h" +LOCAL CHAR Error_File[FNAME_LEN]; +LOCAL CHAR Init_Txt[127]; + + +LOCAL VOID Wall_ServerNotice( CHAR *Msg ); + + GLOBAL VOID Log_Init( VOID ) { - CHAR txt[127]; - #ifdef USE_SYSLOG /* Syslog initialisieren */ openlog( PACKAGE, LOG_CONS|LOG_PID, LOG_LOCAL5 ); @@ -53,49 +57,64 @@ GLOBAL VOID Log_Init( VOID ) Log( LOG_NOTICE, "%s started.", NGIRCd_Version( )); /* Informationen uebern den "Operation Mode" */ - strcpy( txt, "" ); + strcpy( Init_Txt, "" ); #ifdef DEBUG if( NGIRCd_Debug ) { - if( txt[0] ) strcat( txt, ", " ); - strcat( txt, "debug-mode" ); + if( Init_Txt[0] ) strcat( Init_Txt, ", " ); + strcat( Init_Txt, "debug-mode" ); } #endif if( NGIRCd_NoDaemon ) { - if( txt[0] ) strcat( txt, ", " ); - strcat( txt, "no-daemon-mode" ); + if( Init_Txt[0] ) strcat( Init_Txt, ", " ); + strcat( Init_Txt, "no-daemon-mode" ); } if( NGIRCd_Passive ) { - if( txt[0] ) strcat( txt, ", " ); - strcat( txt, "passive-mode" ); + if( Init_Txt[0] ) strcat( Init_Txt, ", " ); + strcat( Init_Txt, "passive-mode" ); } #ifdef SNIFFER if( NGIRCd_Sniffer ) { - if( txt[0] ) strcat( txt, ", " ); - strcat( txt, "network sniffer" ); + if( Init_Txt[0] ) strcat( Init_Txt, ", " ); + strcat( Init_Txt, "network sniffer" ); } #endif - if( txt[0] ) Log( LOG_INFO, "Activating: %s.", txt ); + if( Init_Txt[0] ) Log( LOG_INFO, "Activating: %s.", Init_Txt ); +} /* Log_Init */ + + +GLOBAL VOID Log_InitErrorfile( VOID ) +{ + /* "Error-Log" initialisieren: stderr in Datei umlenken. Dort + * landen z.B. alle Ausgaben von assert()-Aufrufen. */ + + time_t t; - /* stderr in Datei umlenken */ fflush( stderr ); - if( ! freopen( ERROR_FILE, "a+", stderr )) Log( LOG_ERR, "Can't reopen stderr (\""ERROR_FILE"\"): %s", strerror( errno )); + sprintf( Error_File, ERROR_DIR"/"PACKAGE"-%ld.err", (INT32)getpid( )); + if( ! freopen( Error_File, "w", stderr )) + { + Log( LOG_ERR, "Can't reopen stderr (\"%s\"): %s", Error_File, strerror( errno )); + return; + } - fprintf( stderr, "\n--- %s ---\n\n", NGIRCd_StartStr ); - fprintf( stderr, "%s started.\npid=%d, ppid=%d, uid=%d, gid=%d [euid=%d, egid=%d].\nActivating: %s\n\n", NGIRCd_Version( ), getpid( ), getppid( ), getuid( ), getgid( ), geteuid( ), getegid( ), txt[0] ? txt : "-" ); + fputs( ctime( &t ), stderr ); + fprintf( stderr, "%s started.\n", NGIRCd_Version( )); + fprintf( stderr, "Activating: %s\n\n", Init_Txt[0] ? Init_Txt : "-" ); fflush( stderr ); -} /* Log_Init */ +} /* Log_InitErrfile */ GLOBAL VOID Log_Exit( VOID ) { /* Good Bye! */ Log( LOG_NOTICE, PACKAGE" done."); - fprintf( stderr, PACKAGE" done (pid=%d).\n", getpid( )); - fflush( stderr ); + + /* Error-File (stderr) loeschen */ + if( unlink( Error_File ) != 0 ) Log( LOG_ERR, "Can't delete \"%s\": %s", Error_File, strerror( errno )); #ifdef USE_SYSLOG /* syslog abmelden */ @@ -104,15 +123,24 @@ GLOBAL VOID Log_Exit( VOID ) } /* Log_Exit */ -GLOBAL VOID Log( CONST INT Level, CONST CHAR *Format, ... ) +GLOBAL VOID Log( INT Level, CONST CHAR *Format, ... ) { /* Eintrag in Logfile(s) schreiben */ CHAR msg[MAX_LOG_MSG_LEN]; + BOOLEAN snotice; va_list ap; assert( Format != NULL ); + if( Level & LOG_snotice ) + { + /* Notice an User mit "s" Mode */ + snotice = TRUE; + Level &= ~LOG_snotice; + } + else snotice = FALSE; + #ifdef DEBUG if(( Level == LOG_DEBUG ) && ( ! NGIRCd_Debug )) return; #else @@ -124,16 +152,16 @@ GLOBAL VOID Log( CONST INT Level, CONST CHAR *Format, ... ) vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap ); va_end( ap ); - /* In Error-File schreiben */ - if( Level <= LOG_ERR ) fprintf( stderr, "[%d] %s\n", Level, msg ); - - /* ... und ausgeben */ + /* Konsole */ if( NGIRCd_NoDaemon ) printf( "[%d] %s\n", Level, msg ); #ifdef USE_SYSLOG /* Syslog */ syslog( Level, msg ); #endif + + /* lokale User mit "s"-Mode */ + if( snotice ) Wall_ServerNotice( msg ); } /* Log */ @@ -184,4 +212,21 @@ GLOBAL VOID Log_Resolver( CONST INT Level, CONST CHAR *Format, ... ) } /* Log_Resolver */ +LOCAL VOID Wall_ServerNotice( CHAR *Msg ) +{ + /* Server-Notice an entsprechende User verschicken */ + + CLIENT *c; + + assert( Msg != NULL ); + + c = Client_First( ); + while( c ) + { + if(( Client_Conn( c ) > NONE ) && ( Client_HasMode( c, 's' ))) IRC_WriteStrClient( c, "NOTICE %s :%s", Client_ThisServer( ), Msg ); + c = Client_Next( c ); + } +} /* Wall_ServerNotice */ + + /* -eof- */