2001-12-11 22:53:04 +01:00
|
|
|
/*
|
|
|
|
* ngIRCd -- The Next Generation IRC Daemon
|
2002-01-02 03:42:58 +01:00
|
|
|
* Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
|
2001-12-11 22:53:04 +01:00
|
|
|
*
|
2002-12-12 13:24:18 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
* Please read the file COPYING, README and AUTHORS for more information.
|
2001-12-11 22:53:04 +01:00
|
|
|
*
|
2002-12-12 13:24:18 +01:00
|
|
|
* Logging functions
|
2001-12-11 22:53:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2002-03-12 15:37:51 +01:00
|
|
|
#include "portab.h"
|
2001-12-11 22:53:04 +01:00
|
|
|
|
2002-12-19 05:29:59 +01:00
|
|
|
static char UNUSED id[] = "$Id: log.c,v 1.42 2002/12/19 04:30:00 alex Exp $";
|
2002-12-12 13:24:18 +01:00
|
|
|
|
2002-03-12 15:37:51 +01:00
|
|
|
#include "imp.h"
|
2001-12-11 22:53:04 +01:00
|
|
|
#include <assert.h>
|
2002-03-06 16:36:04 +01:00
|
|
|
#include <errno.h>
|
2001-12-11 22:53:04 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
2001-12-26 04:22:16 +01:00
|
|
|
#include <string.h>
|
2002-03-06 16:36:04 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2001-12-27 02:44:49 +01:00
|
|
|
|
|
|
|
#ifdef USE_SYSLOG
|
2001-12-13 00:31:24 +01:00
|
|
|
#include <syslog.h>
|
2001-12-27 02:44:49 +01:00
|
|
|
#endif
|
2001-12-11 22:53:04 +01:00
|
|
|
|
2002-01-11 15:45:37 +01:00
|
|
|
#include "ngircd.h"
|
2002-03-12 15:37:51 +01:00
|
|
|
#include "defines.h"
|
2002-05-27 15:09:26 +02:00
|
|
|
#include "conn.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "channel.h"
|
2002-03-27 21:53:30 +01:00
|
|
|
#include "irc-write.h"
|
2002-01-11 15:45:37 +01:00
|
|
|
|
2002-03-12 15:37:51 +01:00
|
|
|
#include "exp.h"
|
2001-12-11 22:53:04 +01:00
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
|
2002-03-29 21:59:22 +01:00
|
|
|
LOCAL CHAR Error_File[FNAME_LEN];
|
2002-03-30 00:33:42 +01:00
|
|
|
LOCAL CHAR Init_Txt[127];
|
2002-03-29 21:59:22 +01:00
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
LOCAL VOID Wall_ServerNotice PARAMS(( CHAR *Msg ));
|
2002-03-27 21:53:30 +01:00
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL VOID
|
|
|
|
Log_Init( VOID )
|
2001-12-11 22:53:04 +01:00
|
|
|
{
|
2001-12-27 02:44:49 +01:00
|
|
|
#ifdef USE_SYSLOG
|
2002-02-19 21:07:13 +01:00
|
|
|
/* Syslog initialisieren */
|
2001-12-25 20:20:39 +01:00
|
|
|
openlog( PACKAGE, LOG_CONS|LOG_PID, LOG_LOCAL5 );
|
2001-12-27 02:44:49 +01:00
|
|
|
#endif
|
2002-02-19 21:07:13 +01:00
|
|
|
|
|
|
|
/* Hello World! */
|
2002-01-11 15:45:37 +01:00
|
|
|
Log( LOG_NOTICE, "%s started.", NGIRCd_Version( ));
|
2002-03-06 16:36:04 +01:00
|
|
|
|
2002-02-19 21:07:13 +01:00
|
|
|
/* Informationen uebern den "Operation Mode" */
|
2002-03-30 00:33:42 +01:00
|
|
|
strcpy( Init_Txt, "" );
|
2002-02-19 21:07:13 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
if( NGIRCd_Debug )
|
|
|
|
{
|
2002-03-30 00:33:42 +01:00
|
|
|
if( Init_Txt[0] ) strcat( Init_Txt, ", " );
|
|
|
|
strcat( Init_Txt, "debug-mode" );
|
2002-02-19 21:07:13 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if( NGIRCd_NoDaemon )
|
|
|
|
{
|
2002-03-30 00:33:42 +01:00
|
|
|
if( Init_Txt[0] ) strcat( Init_Txt, ", " );
|
|
|
|
strcat( Init_Txt, "no-daemon-mode" );
|
2002-02-19 21:07:13 +01:00
|
|
|
}
|
|
|
|
if( NGIRCd_Passive )
|
|
|
|
{
|
2002-03-30 00:33:42 +01:00
|
|
|
if( Init_Txt[0] ) strcat( Init_Txt, ", " );
|
|
|
|
strcat( Init_Txt, "passive-mode" );
|
2002-02-19 21:07:13 +01:00
|
|
|
}
|
|
|
|
#ifdef SNIFFER
|
|
|
|
if( NGIRCd_Sniffer )
|
|
|
|
{
|
2002-03-30 00:33:42 +01:00
|
|
|
if( Init_Txt[0] ) strcat( Init_Txt, ", " );
|
|
|
|
strcat( Init_Txt, "network sniffer" );
|
2002-02-19 21:07:13 +01:00
|
|
|
}
|
|
|
|
#endif
|
2002-03-30 00:33:42 +01:00
|
|
|
if( Init_Txt[0] ) Log( LOG_INFO, "Activating: %s.", Init_Txt );
|
|
|
|
} /* Log_Init */
|
2002-03-06 16:36:04 +01:00
|
|
|
|
2002-03-30 00:33:42 +01:00
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL VOID
|
|
|
|
Log_InitErrorfile( VOID )
|
2002-03-30 00:33:42 +01:00
|
|
|
{
|
2002-03-29 23:55:42 +01:00
|
|
|
/* "Error-Log" initialisieren: stderr in Datei umlenken. Dort
|
|
|
|
* landen z.B. alle Ausgaben von assert()-Aufrufen. */
|
2002-03-30 00:33:42 +01:00
|
|
|
|
2002-03-31 18:46:15 +02:00
|
|
|
/* Dateiname zusammen bauen */
|
2002-10-09 18:53:02 +02:00
|
|
|
sprintf( Error_File, "%s/%s-%ld.err", ERROR_DIR, PACKAGE, (LONG)getpid( ));
|
2002-03-31 18:46:15 +02:00
|
|
|
|
|
|
|
/* stderr umlenken */
|
|
|
|
fflush( stderr );
|
2002-03-29 23:55:42 +01:00
|
|
|
if( ! freopen( Error_File, "w", stderr ))
|
|
|
|
{
|
|
|
|
Log( LOG_ERR, "Can't reopen stderr (\"%s\"): %s", Error_File, strerror( errno ));
|
|
|
|
return;
|
|
|
|
}
|
2002-03-06 16:36:04 +01:00
|
|
|
|
2002-03-31 18:46:15 +02:00
|
|
|
/* Einige Infos in das Error-File schreiben */
|
2002-03-30 00:58:10 +01:00
|
|
|
fputs( ctime( &NGIRCd_Start ), stderr );
|
2002-03-29 23:55:42 +01:00
|
|
|
fprintf( stderr, "%s started.\n", NGIRCd_Version( ));
|
2002-03-30 00:33:42 +01:00
|
|
|
fprintf( stderr, "Activating: %s\n\n", Init_Txt[0] ? Init_Txt : "-" );
|
2002-03-06 16:36:04 +01:00
|
|
|
fflush( stderr );
|
2002-03-31 18:46:15 +02:00
|
|
|
|
|
|
|
Log( LOG_DEBUG, "Redirected stderr to \"%s\".", Error_File );
|
2002-03-30 00:33:42 +01:00
|
|
|
} /* Log_InitErrfile */
|
2001-12-11 22:53:04 +01:00
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL VOID
|
|
|
|
Log_Exit( VOID )
|
2001-12-11 22:53:04 +01:00
|
|
|
{
|
2002-02-19 21:07:13 +01:00
|
|
|
/* Good Bye! */
|
2002-12-19 05:29:59 +01:00
|
|
|
if( NGIRCd_SignalRestart ) Log( LOG_NOTICE, "%s done (restarting).", PACKAGE );
|
2002-06-02 19:03:32 +02:00
|
|
|
else Log( LOG_NOTICE, "%s done.", PACKAGE );
|
2002-03-21 13:00:23 +01:00
|
|
|
|
2002-03-29 21:59:22 +01:00
|
|
|
/* Error-File (stderr) loeschen */
|
|
|
|
if( unlink( Error_File ) != 0 ) Log( LOG_ERR, "Can't delete \"%s\": %s", Error_File, strerror( errno ));
|
|
|
|
|
2001-12-27 02:44:49 +01:00
|
|
|
#ifdef USE_SYSLOG
|
2002-02-19 21:07:13 +01:00
|
|
|
/* syslog abmelden */
|
2001-12-13 00:31:24 +01:00
|
|
|
closelog( );
|
2001-12-27 02:44:49 +01:00
|
|
|
#endif
|
2001-12-11 22:53:04 +01:00
|
|
|
} /* Log_Exit */
|
|
|
|
|
|
|
|
|
2002-05-30 18:52:20 +02:00
|
|
|
#ifdef PROTOTYPES
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL VOID
|
|
|
|
Log( INT Level, CONST CHAR *Format, ... )
|
2002-05-30 18:52:20 +02:00
|
|
|
#else
|
|
|
|
GLOBAL VOID
|
|
|
|
Log( Level, Format, va_alist )
|
|
|
|
INT Level;
|
|
|
|
CONST CHAR *Format;
|
|
|
|
va_dcl
|
|
|
|
#endif
|
2001-12-11 22:53:04 +01:00
|
|
|
{
|
|
|
|
/* Eintrag in Logfile(s) schreiben */
|
|
|
|
|
|
|
|
CHAR msg[MAX_LOG_MSG_LEN];
|
2002-03-27 21:53:30 +01:00
|
|
|
BOOLEAN snotice;
|
2001-12-11 22:53:04 +01:00
|
|
|
va_list ap;
|
|
|
|
|
2001-12-29 21:16:31 +01:00
|
|
|
assert( Format != NULL );
|
|
|
|
|
2002-03-27 21:53:30 +01:00
|
|
|
if( Level & LOG_snotice )
|
|
|
|
{
|
|
|
|
/* Notice an User mit "s" Mode */
|
|
|
|
snotice = TRUE;
|
|
|
|
Level &= ~LOG_snotice;
|
|
|
|
}
|
2002-03-29 23:55:42 +01:00
|
|
|
else snotice = FALSE;
|
2002-03-27 21:53:30 +01:00
|
|
|
|
2002-01-11 15:45:37 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
if(( Level == LOG_DEBUG ) && ( ! NGIRCd_Debug )) return;
|
|
|
|
#else
|
2001-12-25 23:04:26 +01:00
|
|
|
if( Level == LOG_DEBUG ) return;
|
|
|
|
#endif
|
|
|
|
|
2001-12-11 22:53:04 +01:00
|
|
|
/* String mit variablen Argumenten zusammenbauen ... */
|
2002-05-30 18:52:20 +02:00
|
|
|
#ifdef PROTOTYPES
|
2001-12-11 22:53:04 +01:00
|
|
|
va_start( ap, Format );
|
2002-05-30 18:52:20 +02:00
|
|
|
#else
|
|
|
|
va_start( ap );
|
|
|
|
#endif
|
2002-03-03 18:17:01 +01:00
|
|
|
vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
|
|
|
|
va_end( ap );
|
2001-12-11 22:53:04 +01:00
|
|
|
|
2002-03-30 14:37:12 +01:00
|
|
|
if( NGIRCd_NoDaemon )
|
|
|
|
{
|
|
|
|
/* auf Konsole ausgeben */
|
2002-09-03 19:25:45 +02:00
|
|
|
fprintf( stdout, "[%d] %s\n", Level, msg );
|
|
|
|
fflush( stdout );
|
2002-03-30 14:37:12 +01:00
|
|
|
}
|
2002-09-10 00:55:21 +02:00
|
|
|
#ifdef USE_SYSLOG
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Syslog */
|
2002-10-04 13:21:46 +02:00
|
|
|
syslog( Level, "%s", msg );
|
2002-09-10 00:55:21 +02:00
|
|
|
}
|
|
|
|
#endif
|
2002-03-30 14:37:12 +01:00
|
|
|
|
|
|
|
if( Level <= LOG_CRIT )
|
|
|
|
{
|
|
|
|
/* Kritische Meldungen in Error-File (stderr) */
|
|
|
|
fprintf( stderr, "%s\n", msg );
|
|
|
|
fflush( stderr );
|
|
|
|
}
|
2002-03-06 16:36:04 +01:00
|
|
|
|
2002-03-30 14:37:12 +01:00
|
|
|
if( snotice )
|
|
|
|
{
|
|
|
|
/* NOTICE an lokale User mit "s"-Mode */
|
|
|
|
Wall_ServerNotice( msg );
|
|
|
|
}
|
2001-12-11 22:53:04 +01:00
|
|
|
} /* Log */
|
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL VOID
|
|
|
|
Log_Init_Resolver( VOID )
|
2001-12-29 21:16:31 +01:00
|
|
|
{
|
|
|
|
#ifdef USE_SYSLOG
|
|
|
|
openlog( PACKAGE, LOG_CONS|LOG_PID, LOG_LOCAL5 );
|
|
|
|
#endif
|
|
|
|
} /* Log_Init_Resolver */
|
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL VOID
|
|
|
|
Log_Exit_Resolver( VOID )
|
2001-12-29 21:16:31 +01:00
|
|
|
{
|
|
|
|
#ifdef USE_SYSLOG
|
|
|
|
closelog( );
|
|
|
|
#endif
|
|
|
|
} /* Log_Exit_Resolver */
|
|
|
|
|
|
|
|
|
2002-05-30 18:52:20 +02:00
|
|
|
#ifdef PROTOTYPES
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL VOID
|
|
|
|
Log_Resolver( CONST INT Level, CONST CHAR *Format, ... )
|
2002-05-30 18:52:20 +02:00
|
|
|
#else
|
|
|
|
GLOBAL VOID
|
|
|
|
Log_Resolver( Level, Format, va_alist )
|
|
|
|
CONST INT Level;
|
|
|
|
CONST CHAR *Format;
|
|
|
|
va_dcl
|
|
|
|
#endif
|
2001-12-29 21:16:31 +01:00
|
|
|
{
|
|
|
|
/* Eintrag des Resolver in Logfile(s) schreiben */
|
|
|
|
|
2002-01-05 16:54:40 +01:00
|
|
|
#ifndef USE_SYSLOG
|
|
|
|
return;
|
|
|
|
#else
|
|
|
|
|
2001-12-29 21:16:31 +01:00
|
|
|
CHAR msg[MAX_LOG_MSG_LEN];
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
assert( Format != NULL );
|
|
|
|
|
2002-09-10 00:55:21 +02:00
|
|
|
if( NGIRCd_NoDaemon ) return;
|
|
|
|
|
2002-01-11 15:45:37 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
if(( Level == LOG_DEBUG ) && ( ! NGIRCd_Debug )) return;
|
|
|
|
#else
|
2001-12-29 21:16:31 +01:00
|
|
|
if( Level == LOG_DEBUG ) return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* String mit variablen Argumenten zusammenbauen ... */
|
2002-05-30 18:52:20 +02:00
|
|
|
#ifdef PROTOTYPES
|
2001-12-29 21:16:31 +01:00
|
|
|
va_start( ap, Format );
|
2002-05-30 18:52:20 +02:00
|
|
|
#else
|
|
|
|
va_start( ap );
|
|
|
|
#endif
|
2002-03-03 18:17:01 +01:00
|
|
|
vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
|
|
|
|
va_end( ap );
|
2001-12-29 21:16:31 +01:00
|
|
|
|
|
|
|
/* ... und ausgeben */
|
|
|
|
syslog( Level, msg );
|
|
|
|
|
2002-01-05 16:54:40 +01:00
|
|
|
#endif
|
2001-12-29 21:16:31 +01:00
|
|
|
} /* Log_Resolver */
|
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
LOCAL VOID
|
|
|
|
Wall_ServerNotice( CHAR *Msg )
|
2002-03-27 21:53:30 +01:00
|
|
|
{
|
2002-03-29 23:55:42 +01:00
|
|
|
/* Server-Notice an entsprechende User verschicken */
|
|
|
|
|
2002-03-27 21:53:30 +01:00
|
|
|
CLIENT *c;
|
|
|
|
|
|
|
|
assert( Msg != NULL );
|
2002-03-29 23:55:42 +01:00
|
|
|
|
2002-03-27 21:53:30 +01:00
|
|
|
c = Client_First( );
|
|
|
|
while( c )
|
|
|
|
{
|
2002-10-09 15:15:18 +02:00
|
|
|
if(( Client_Conn( c ) > NONE ) && ( Client_HasMode( c, 's' ))) IRC_WriteStrClient( c, "NOTICE %s :%s%s", Client_ThisServer( ), NOTICE_TXTPREFIX, Msg );
|
2002-03-27 21:53:30 +01:00
|
|
|
c = Client_Next( c );
|
|
|
|
}
|
|
|
|
} /* Wall_ServerNotice */
|
|
|
|
|
|
|
|
|
2001-12-11 22:53:04 +01:00
|
|
|
/* -eof- */
|