X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Flog.c;h=5b3911a550701f223d9465495d0d12c2c8699cf8;hp=4ebe4e0319c2804f5e31a4861ad766ea8f5ca82e;hb=1c00ddffec83f60c37e5f1885b08256d563c6464;hpb=1547f76cfdfabe2226af2e35196316b21a32937c diff --git a/src/ngircd/log.c b/src/ngircd/log.c index 4ebe4e03..5b3911a5 100644 --- a/src/ngircd/log.c +++ b/src/ngircd/log.c @@ -9,148 +9,164 @@ * 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.15 2002/01/02 02:42:58 alex Exp $ + * $Id: log.c,v 1.27 2002/03/29 20:59:22 alex Exp $ * * log.c: Logging-Funktionen - * - * $Log: log.c,v $ - * Revision 1.15 2002/01/02 02:42:58 alex - * - Copyright-Texte aktualisiert. - * - * Revision 1.14 2002/01/01 18:01:43 alex - * - Architektur und Betriebssystem in Start-Meldung aufgenommen. - * - * Revision 1.13 2001/12/31 02:18:51 alex - * - viele neue Befehle (WHOIS, ISON, OPER, DIE, RESTART), - * - neuen Header "defines.h" mit (fast) allen Konstanten. - * - Code Cleanups und viele "kleine" Aenderungen & Bugfixes. - * - * Revision 1.12 2001/12/29 20:16:31 alex - * - Log-Funktionen fuer Resolver-Sub-Prozess implementiert. - * - * Revision 1.11 2001/12/29 03:08:49 alex - * - neue configure-Option "--enable-strict-rfc". - * - * Revision 1.10 2001/12/27 01:44:49 alex - * - die Verwendung von syslog kann nun abgeschaltet werden. - * - * Revision 1.9 2001/12/26 03:22:16 alex - * - string.h wird nun includiert. - * - * Revision 1.8 2001/12/25 23:13:00 alex - * - Versionsstring bei Programmstart verbessert. - * - * Revision 1.7 2001/12/25 22:04:26 alex - * - Aenderungen an den Debug- und Logging-Funktionen. - * - * Revision 1.6 2001/12/25 19:20:39 alex - * - es wird nun die Facility LOG_LOCAL5 zum Loggen verwendet. - * - * Revision 1.5 2001/12/15 00:07:56 alex - * - Log-Level der Start- und Stop-Meldungen angehoben. - * - * Revision 1.4 2001/12/13 02:04:16 alex - * - boesen "Speicherschiesser" in Log() gefixt. - * - * Revision 1.3 2001/12/12 23:31:24 alex - * - Zum Loggen wird nun auch syslog verwendet. - * - * Revision 1.2 2001/12/12 17:19:12 alex - * - in Log-Meldungen wird nun auch der Level der Meldung ausgegeben. - * - * Revision 1.1.1.1 2001/12/11 21:53:04 alex - * - Imported sources to CVS. */ -#define MAX_LOG_MSG_LEN 256 +#include "portab.h" - -#include -#include "global.h" - -#include +#include "imp.h" #include +#include #include #include #include +#include +#include #ifdef USE_SYSLOG #include #endif -#include +#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 VOID Wall_ServerNotice( CHAR *Msg ); + + GLOBAL VOID Log_Init( VOID ) { - CHAR txt[64]; - - strcpy( txt, "" ); + CHAR txt[127]; #ifdef USE_SYSLOG - if( txt[0] ) strcat( txt, "+" ); - else strcat( txt, "-" ); - strcat( txt, "SYSLOG" ); -#endif -#ifdef STRICT_RFC - if( txt[0] ) strcat( txt, "+" ); - else strcat( txt, "-" ); - strcat( txt, "RFC" ); + /* Syslog initialisieren */ + openlog( PACKAGE, LOG_CONS|LOG_PID, LOG_LOCAL5 ); #endif + + /* Hello World! */ + Log( LOG_NOTICE, "%s started.", NGIRCd_Version( )); + + /* Informationen uebern den "Operation Mode" */ + strcpy( txt, "" ); #ifdef DEBUG - if( txt[0] ) strcat( txt, "+" ); - else strcat( txt, "-" ); - strcat( txt, "DEBUG" ); + if( NGIRCd_Debug ) + { + if( txt[0] ) strcat( txt, ", " ); + strcat( txt, "debug-mode" ); + } #endif + if( NGIRCd_NoDaemon ) + { + if( txt[0] ) strcat( txt, ", " ); + strcat( txt, "no-daemon-mode" ); + } + if( NGIRCd_Passive ) + { + if( txt[0] ) strcat( txt, ", " ); + strcat( txt, "passive-mode" ); + } #ifdef SNIFFER - if( txt[0] ) strcat( txt, "+" ); - else strcat( txt, "-" ); - strcat( txt, "SNIFFER" ); + if( NGIRCd_Sniffer ) + { + if( txt[0] ) strcat( txt, ", " ); + strcat( txt, "network sniffer" ); + } #endif + if( txt[0] ) Log( LOG_INFO, "Activating: %s.", txt ); -#ifdef USE_SYSLOG - openlog( PACKAGE, LOG_CONS|LOG_PID, LOG_LOCAL5 ); -#endif - Log( LOG_NOTICE, PACKAGE" version "VERSION"%s-"P_OSNAME"/"P_ARCHNAME" started.", txt ); + /* stderr in Datei umlenken */ + sprintf( Error_File, ERROR_DIR"/"PACKAGE"-%ld.err", (INT32)getpid( )); + fflush( stderr ); + if( ! freopen( Error_File, "a+", stderr )) Log( LOG_ERR, "Can't reopen stderr (\"%s\"): %s", Error_File, strerror( errno )); + + fprintf( stderr, "\n--- %s ---\n\n", NGIRCd_StartStr ); + fprintf( stderr, "%s started.\npid=%ld, ppid=%ld, uid=%ld, gid=%ld [euid=%ld, egid=%ld].\nActivating: %s\n\n", NGIRCd_Version( ), (INT32)getpid( ), (INT32)getppid( ), (INT32)getuid( ), (INT32)getgid( ), (INT32)geteuid( ), (INT32)getegid( ), txt[0] ? txt : "-" ); + fflush( stderr ); } /* Log_Init */ GLOBAL VOID Log_Exit( VOID ) { + time_t t; + + /* Good Bye! */ Log( LOG_NOTICE, PACKAGE" done."); + + t = time( NULL ); + fputs( ctime( &t ), stderr ); + fprintf( stderr, PACKAGE" done (pid=%ld).\n", (INT32)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 */ closelog( ); #endif } /* 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; + time_t t; assert( Format != NULL ); -#ifndef DEBUG + snotice = FALSE; + + if( Level & LOG_snotice ) + { + /* Notice an User mit "s" Mode */ + snotice = TRUE; + Level &= ~LOG_snotice; + } + +#ifdef DEBUG + if(( Level == LOG_DEBUG ) && ( ! NGIRCd_Debug )) return; +#else if( Level == LOG_DEBUG ) return; #endif /* String mit variablen Argumenten zusammenbauen ... */ va_start( ap, Format ); - vsnprintf( msg, MAX_LOG_MSG_LEN - 1, Format, ap ); - msg[MAX_LOG_MSG_LEN - 1] = '\0'; + vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap ); + va_end( ap ); + + /* In Error-File schreiben */ + if( Level <= LOG_ERR ) + { + t = time( NULL ); + fputs( ctime( &t ), stderr ); + fprintf( stderr, "[%d] %s\n\n", Level, msg ); + } + + /* Konsole */ + if( NGIRCd_NoDaemon ) printf( "[%d] %s\n", Level, msg ); - /* ... und ausgeben */ - printf( "[%d] %s\n", Level, msg ); #ifdef USE_SYSLOG + /* Syslog */ syslog( Level, msg ); #endif - va_end( ap ); + /* lokale User mit "s"-Mode */ + if( snotice ) Wall_ServerNotice( msg ); } /* Log */ @@ -174,29 +190,46 @@ GLOBAL VOID Log_Resolver( CONST INT Level, CONST CHAR *Format, ... ) { /* Eintrag des Resolver in Logfile(s) schreiben */ +#ifndef USE_SYSLOG + return; +#else + CHAR msg[MAX_LOG_MSG_LEN]; va_list ap; assert( Format != NULL ); -#ifndef USE_SYSLOG - return; -#endif - -#ifndef DEBUG +#ifdef DEBUG + if(( Level == LOG_DEBUG ) && ( ! NGIRCd_Debug )) return; +#else if( Level == LOG_DEBUG ) return; #endif /* String mit variablen Argumenten zusammenbauen ... */ va_start( ap, Format ); - vsnprintf( msg, MAX_LOG_MSG_LEN - 1, Format, ap ); - msg[MAX_LOG_MSG_LEN - 1] = '\0'; + vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap ); + va_end( ap ); /* ... und ausgeben */ syslog( Level, msg ); - va_end( ap ); +#endif } /* Log_Resolver */ +LOCAL VOID Wall_ServerNotice( CHAR *Msg ) +{ + 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- */