X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Flog.c;h=394817b0277de1a070141cb84f88b0657888975e;hp=7f58a1b98922ef30c37b696e025cab550fd99e87;hb=ca33cbda05902b0009058d369f88c0a7a43b1bbe;hpb=804b1ec4987ed3beb4759cc480b2c6c911627b7e diff --git a/src/ngircd/log.c b/src/ngircd/log.c index 7f58a1b9..394817b0 100644 --- a/src/ngircd/log.c +++ b/src/ngircd/log.c @@ -1,6 +1,6 @@ /* * ngIRCd -- The Next Generation IRC Daemon - * Copyright (c)2001 by Alexander Barton (alex@barton.de) + * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de) * * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen * der GNU General Public License (GPL), wie von der Free Software Foundation @@ -9,112 +9,96 @@ * 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.13 2001/12/31 02:18:51 alex Exp $ + * $Id: log.c,v 1.21 2002/03/12 14:37:52 alex Exp $ * * log.c: Logging-Funktionen - * - * $Log: log.c,v $ - * 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 -#include "global.h" +#include "portab.h" -#include +#include "imp.h" #include +#include #include #include #include +#include +#include #ifdef USE_SYSLOG #include #endif -#include +#include "ngircd.h" +#include "defines.h" + +#include "exp.h" #include "log.h" 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 started.", txt ); + /* stderr in Datei umlenken */ + fflush( stderr ); + if( ! freopen( ERROR_FILE, "a+", stderr )) Log( LOG_ERR, "Can't reopen stderr (\""ERROR_FILE"\"): %s", strerror( errno )); + + 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 : "-" ); + fflush( stderr ); } /* Log_Init */ GLOBAL VOID Log_Exit( VOID ) { + /* Good Bye! */ Log( LOG_NOTICE, PACKAGE" done."); + fprintf( stderr, PACKAGE" done (pid=%d).\n", getpid( )); + fflush( stderr ); + #ifdef USE_SYSLOG + /* syslog abmelden */ closelog( ); #endif } /* Log_Exit */ @@ -129,22 +113,27 @@ GLOBAL VOID Log( CONST INT Level, CONST CHAR *Format, ... ) assert( Format != NULL ); -#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 ); + + /* In Error-File schreiben */ + if( Level <= LOG_ERR ) fprintf( stderr, "[%d] %s\n", Level, msg ); /* ... und ausgeben */ - printf( "[%d] %s\n", Level, msg ); + if( NGIRCd_NoDaemon ) printf( "[%d] %s\n", Level, msg ); + #ifdef USE_SYSLOG + /* Syslog */ syslog( Level, msg ); #endif - - va_end( ap ); } /* Log */ @@ -168,28 +157,30 @@ 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 */