2001-12-11 22:53:04 +01:00
|
|
|
/*
|
|
|
|
* ngIRCd -- The Next Generation IRC Daemon
|
2014-03-17 02:13:15 +01:00
|
|
|
* Copyright (c)2001-2014 Alexander Barton (alex@barton.de) and Contributors.
|
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-03-12 15:37:51 +01:00
|
|
|
#include "portab.h"
|
2001-12-11 22:53:04 +01:00
|
|
|
|
2010-12-27 17:14:14 +01:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Logging functions
|
|
|
|
*/
|
|
|
|
|
2001-12-11 22:53:04 +01:00
|
|
|
#include <assert.h>
|
2004-10-20 15:47:32 +02:00
|
|
|
#ifdef PROTOTYPES
|
2014-03-17 02:28:39 +01:00
|
|
|
# include <stdarg.h>
|
2004-10-20 15:47:32 +02:00
|
|
|
#else
|
2014-03-17 02:28:39 +01:00
|
|
|
# include <varargs.h>
|
2004-10-20 15:47:32 +02:00
|
|
|
#endif
|
2001-12-11 22:53:04 +01:00
|
|
|
#include <stdio.h>
|
2002-03-06 16:36:04 +01:00
|
|
|
#include <sys/types.h>
|
2014-03-17 02:28:39 +01:00
|
|
|
#include <time.h>
|
2002-03-06 16:36:04 +01:00
|
|
|
#include <unistd.h>
|
2001-12-27 02:44:49 +01:00
|
|
|
|
2003-12-26 16:55:07 +01:00
|
|
|
#ifdef SYSLOG
|
2014-03-17 02:28:39 +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-05-27 15:09:26 +02:00
|
|
|
#include "conn.h"
|
|
|
|
#include "channel.h"
|
2002-03-27 21:53:30 +01:00
|
|
|
#include "irc-write.h"
|
2010-09-24 17:39:11 +02:00
|
|
|
#include "conf.h"
|
2002-01-11 15:45:37 +01:00
|
|
|
|
2001-12-11 22:53:04 +01:00
|
|
|
#include "log.h"
|
|
|
|
|
2005-07-31 22:13:07 +02:00
|
|
|
static bool Is_Daemon;
|
2002-03-29 21:59:22 +01:00
|
|
|
|
2005-06-24 21:55:10 +02:00
|
|
|
|
2008-12-17 23:27:25 +01:00
|
|
|
static void
|
|
|
|
Log_Message(int Level, const char *msg)
|
|
|
|
{
|
|
|
|
if (!Is_Daemon) {
|
|
|
|
/* log to console */
|
|
|
|
fprintf(stdout, "[%ld:%d %4ld] %s\n", (long)getpid(), Level,
|
2013-08-25 01:07:06 +02:00
|
|
|
(long)(time(NULL) - NGIRCd_Start), msg);
|
2008-12-17 23:27:25 +01:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
#ifdef SYSLOG
|
|
|
|
else {
|
|
|
|
syslog(Level, "%s", msg);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-03-27 21:53:30 +01:00
|
|
|
|
2012-02-14 11:01:13 +01:00
|
|
|
/**
|
|
|
|
* Initialitze logging.
|
|
|
|
* This function is called before the configuration file is read in.
|
|
|
|
*
|
|
|
|
* @param Daemon_Mode Set to true if ngIRCd is running as daemon.
|
|
|
|
*/
|
2005-03-19 19:43:48 +01:00
|
|
|
GLOBAL void
|
2012-02-14 10:32:58 +01:00
|
|
|
Log_Init(bool Daemon_Mode)
|
2001-12-11 22:53:04 +01:00
|
|
|
{
|
2005-06-24 21:55:10 +02:00
|
|
|
Is_Daemon = Daemon_Mode;
|
2012-02-14 10:32:58 +01:00
|
|
|
|
2003-12-26 16:55:07 +01:00
|
|
|
#ifdef SYSLOG
|
2010-09-24 17:39:11 +02:00
|
|
|
#ifndef LOG_CONS /* Kludge: mips-dec-ultrix4.5 has no LOG_CONS */
|
2005-04-16 11:31:30 +02:00
|
|
|
#define LOG_CONS 0
|
|
|
|
#endif
|
2012-03-02 09:41:13 +01:00
|
|
|
#ifdef LOG_DAEMON
|
2012-10-29 10:24:27 +01:00
|
|
|
openlog(PACKAGE, LOG_CONS|LOG_PID, LOG_DAEMON);
|
2012-03-02 09:41:13 +01:00
|
|
|
#else
|
2012-10-29 10:24:27 +01:00
|
|
|
openlog(PACKAGE, LOG_CONS|LOG_PID, 0);
|
2012-03-02 09:41:13 +01:00
|
|
|
#endif
|
2001-12-27 02:44:49 +01:00
|
|
|
#endif
|
2002-03-30 00:33:42 +01:00
|
|
|
} /* Log_Init */
|
2002-03-06 16:36:04 +01:00
|
|
|
|
2002-03-30 00:33:42 +01:00
|
|
|
|
2012-02-14 11:01:13 +01:00
|
|
|
/**
|
|
|
|
* Re-init logging after reading the configuration file.
|
|
|
|
*/
|
|
|
|
GLOBAL void
|
|
|
|
Log_ReInit(void)
|
|
|
|
{
|
|
|
|
#ifdef SYSLOG
|
|
|
|
#ifndef LOG_CONS /* Kludge: mips-dec-ultrix4.5 has no LOG_CONS */
|
|
|
|
#define LOG_CONS 0
|
|
|
|
#endif
|
|
|
|
closelog();
|
2012-10-29 10:24:27 +01:00
|
|
|
openlog(PACKAGE, LOG_CONS|LOG_PID, Conf_SyslogFacility);
|
2012-02-14 11:01:13 +01:00
|
|
|
#endif
|
|
|
|
Log(LOG_NOTICE, "%s started.", NGIRCd_Version);
|
2012-03-02 09:41:13 +01:00
|
|
|
Log(LOG_INFO, "Using configuration file \"%s\" ...", NGIRCd_ConfFile);
|
2012-02-14 11:01:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-19 19:43:48 +01:00
|
|
|
GLOBAL void
|
|
|
|
Log_Exit( void )
|
2001-12-11 22:53:04 +01:00
|
|
|
{
|
2013-02-10 20:18:44 +01:00
|
|
|
Log(LOG_INFO, "%s done%s, served %lu connection%s.", PACKAGE_NAME,
|
2013-01-27 23:22:00 +01:00
|
|
|
NGIRCd_SignalRestart ? " (restarting)" : "", Conn_CountAccepted(),
|
|
|
|
Conn_CountAccepted() == 1 ? "" : "s");
|
2003-12-26 16:55:07 +01:00
|
|
|
#ifdef SYSLOG
|
2009-04-21 08:40:10 +02:00
|
|
|
closelog();
|
2001-12-27 02:44:49 +01:00
|
|
|
#endif
|
2001-12-11 22:53:04 +01:00
|
|
|
} /* Log_Exit */
|
|
|
|
|
|
|
|
|
2006-07-24 01:23:45 +02:00
|
|
|
/**
|
|
|
|
* Log function for debug messages.
|
|
|
|
* This function is only functional when the program is compiled with debug
|
|
|
|
* code enabled; otherwise it is an empty function which the compiler will
|
2006-08-05 11:16:21 +02:00
|
|
|
* hopefully mangle down to "nothing" (see log.h). Therefore you should use
|
|
|
|
* LogDebug(...) in favor to Log(LOG_DEBUG, ...).
|
2006-07-24 01:23:45 +02:00
|
|
|
* @param Format Format string like printf().
|
|
|
|
* @param ... Further arguments.
|
|
|
|
*/
|
2006-08-05 11:16:21 +02:00
|
|
|
#ifdef DEBUG
|
2006-02-08 18:33:28 +01:00
|
|
|
# ifdef PROTOTYPES
|
|
|
|
GLOBAL void
|
|
|
|
LogDebug( const char *Format, ... )
|
|
|
|
# else
|
|
|
|
GLOBAL void
|
|
|
|
LogDebug( Format, va_alist )
|
|
|
|
const char *Format;
|
|
|
|
va_dcl
|
2006-07-24 01:23:45 +02:00
|
|
|
# endif /* PROTOTYPES */
|
2006-02-08 18:33:28 +01:00
|
|
|
{
|
|
|
|
char msg[MAX_LOG_MSG_LEN];
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
if (!NGIRCd_Debug) return;
|
|
|
|
#ifdef PROTOTYPES
|
|
|
|
va_start( ap, Format );
|
|
|
|
#else
|
|
|
|
va_start( ap );
|
|
|
|
#endif
|
|
|
|
vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
|
|
|
|
va_end( ap );
|
|
|
|
Log(LOG_DEBUG, "%s", msg);
|
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2006-08-05 11:16:21 +02:00
|
|
|
|
2006-07-24 01:23:45 +02:00
|
|
|
/**
|
|
|
|
* Logging function of ngIRCd.
|
|
|
|
* This function logs messages to the console and/or syslog, whichever is
|
|
|
|
* suitable for the mode ngIRCd is running in (daemon vs. non-daemon).
|
2008-11-17 23:27:06 +01:00
|
|
|
* If LOG_snotice is set, the log messages goes to all user with the mode +s
|
|
|
|
* set and the local &SERVER channel, too.
|
2013-08-04 13:33:10 +02:00
|
|
|
* Please note: you should use LogDebug(...) for debug messages!
|
2006-07-24 01:23:45 +02:00
|
|
|
* @param Level syslog level (LOG_xxx)
|
|
|
|
* @param Format Format string like printf().
|
|
|
|
* @param ... Further arguments.
|
|
|
|
*/
|
2002-05-30 18:52:20 +02:00
|
|
|
#ifdef PROTOTYPES
|
2005-03-19 19:43:48 +01:00
|
|
|
GLOBAL void
|
|
|
|
Log( int Level, const char *Format, ... )
|
2002-05-30 18:52:20 +02:00
|
|
|
#else
|
2005-03-19 19:43:48 +01:00
|
|
|
GLOBAL void
|
2002-05-30 18:52:20 +02:00
|
|
|
Log( Level, Format, va_alist )
|
2005-03-19 19:43:48 +01:00
|
|
|
int Level;
|
|
|
|
const char *Format;
|
2002-05-30 18:52:20 +02:00
|
|
|
va_dcl
|
|
|
|
#endif
|
2001-12-11 22:53:04 +01:00
|
|
|
{
|
2005-03-19 19:43:48 +01:00
|
|
|
char msg[MAX_LOG_MSG_LEN];
|
|
|
|
bool 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 */
|
2005-03-19 19:43:48 +01:00
|
|
|
snotice = true;
|
2002-03-27 21:53:30 +01:00
|
|
|
Level &= ~LOG_snotice;
|
|
|
|
}
|
2005-03-19 19:43:48 +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
|
|
|
|
|
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
|
|
|
|
2008-12-17 23:27:25 +01:00
|
|
|
Log_Message(Level, msg);
|
2002-03-30 14:37:12 +01:00
|
|
|
|
2008-11-17 23:27:06 +01:00
|
|
|
if (snotice) {
|
|
|
|
/* Send NOTICE to all local users with mode +s and to the
|
|
|
|
* local &SERVER channel */
|
2010-05-22 17:10:22 +02:00
|
|
|
Log_ServerNotice('s', "%s", msg);
|
2008-11-17 23:27:06 +01:00
|
|
|
Channel_LogServer(msg);
|
2002-03-30 14:37:12 +01:00
|
|
|
}
|
2001-12-11 22:53:04 +01:00
|
|
|
} /* Log */
|
|
|
|
|
|
|
|
|
2005-03-19 19:43:48 +01:00
|
|
|
GLOBAL void
|
2010-07-13 16:50:00 +02:00
|
|
|
Log_Init_Subprocess(char UNUSED *Name)
|
2001-12-29 21:16:31 +01:00
|
|
|
{
|
2003-12-26 16:55:07 +01:00
|
|
|
#ifdef SYSLOG
|
2012-10-29 10:24:27 +01:00
|
|
|
openlog(PACKAGE, LOG_CONS|LOG_PID, Conf_SyslogFacility);
|
2001-12-29 21:16:31 +01:00
|
|
|
#endif
|
2005-06-24 21:20:56 +02:00
|
|
|
#ifdef DEBUG
|
2010-07-01 00:34:56 +02:00
|
|
|
Log_Subprocess(LOG_DEBUG, "%s sub-process starting, PID %ld.",
|
|
|
|
Name, (long)getpid());
|
2005-06-24 21:20:56 +02:00
|
|
|
#endif
|
2010-07-01 00:34:56 +02:00
|
|
|
}
|
2001-12-29 21:16:31 +01:00
|
|
|
|
|
|
|
|
2005-03-19 19:43:48 +01:00
|
|
|
GLOBAL void
|
2010-07-13 16:50:00 +02:00
|
|
|
Log_Exit_Subprocess(char UNUSED *Name)
|
2001-12-29 21:16:31 +01:00
|
|
|
{
|
2005-06-24 21:20:56 +02:00
|
|
|
#ifdef DEBUG
|
2010-07-01 00:34:56 +02:00
|
|
|
Log_Subprocess(LOG_DEBUG, "%s sub-process %ld done.",
|
|
|
|
Name, (long)getpid());
|
2005-06-24 21:20:56 +02:00
|
|
|
#endif
|
2003-12-26 16:55:07 +01:00
|
|
|
#ifdef SYSLOG
|
2001-12-29 21:16:31 +01:00
|
|
|
closelog( );
|
|
|
|
#endif
|
2010-07-01 00:34:56 +02:00
|
|
|
}
|
2001-12-29 21:16:31 +01:00
|
|
|
|
|
|
|
|
2002-05-30 18:52:20 +02:00
|
|
|
#ifdef PROTOTYPES
|
2005-03-19 19:43:48 +01:00
|
|
|
GLOBAL void
|
2010-07-01 00:34:56 +02:00
|
|
|
Log_Subprocess(const int Level, const char *Format, ...)
|
2002-05-30 18:52:20 +02:00
|
|
|
#else
|
2005-03-19 19:43:48 +01:00
|
|
|
GLOBAL void
|
2010-07-01 00:34:56 +02:00
|
|
|
Log_Subprocess(Level, Format, va_alist)
|
2005-03-19 19:43:48 +01:00
|
|
|
const int Level;
|
|
|
|
const char *Format;
|
2002-05-30 18:52:20 +02:00
|
|
|
va_dcl
|
|
|
|
#endif
|
2001-12-29 21:16:31 +01:00
|
|
|
{
|
2005-03-19 19:43:48 +01:00
|
|
|
char msg[MAX_LOG_MSG_LEN];
|
2001-12-29 21:16:31 +01:00
|
|
|
va_list ap;
|
|
|
|
|
2010-07-01 00:34:56 +02:00
|
|
|
assert(Format != NULL);
|
2001-12-29 21:16:31 +01:00
|
|
|
|
2002-01-11 15:45:37 +01:00
|
|
|
#ifdef DEBUG
|
2010-07-01 00:34:56 +02:00
|
|
|
if ((Level == LOG_DEBUG) && (!NGIRCd_Debug))
|
|
|
|
return;
|
2002-01-11 15:45:37 +01:00
|
|
|
#else
|
2010-07-01 00:34:56 +02:00
|
|
|
if (Level == LOG_DEBUG)
|
|
|
|
return;
|
2001-12-29 21:16:31 +01:00
|
|
|
#endif
|
|
|
|
|
2002-05-30 18:52:20 +02:00
|
|
|
#ifdef PROTOTYPES
|
2010-07-01 00:34:56 +02:00
|
|
|
va_start(ap, Format);
|
2002-05-30 18:52:20 +02:00
|
|
|
#else
|
2010-07-01 00:34:56 +02:00
|
|
|
va_start(ap);
|
2002-05-30 18:52:20 +02:00
|
|
|
#endif
|
2010-07-01 00:34:56 +02:00
|
|
|
vsnprintf(msg, MAX_LOG_MSG_LEN, Format, ap);
|
|
|
|
va_end(ap);
|
2001-12-29 21:16:31 +01:00
|
|
|
|
2008-12-17 23:27:25 +01:00
|
|
|
Log_Message(Level, msg);
|
2010-07-01 00:34:56 +02:00
|
|
|
}
|
2001-12-29 21:16:31 +01:00
|
|
|
|
|
|
|
|
2005-08-29 12:58:00 +02:00
|
|
|
/**
|
2010-05-22 17:10:22 +02:00
|
|
|
* Send a log message to all local users flagged with the given user mode.
|
|
|
|
* @param UserMode User mode which the target user must have set,
|
|
|
|
* @param Format The format string.
|
2005-08-29 12:58:00 +02:00
|
|
|
*/
|
2010-05-22 17:10:22 +02:00
|
|
|
#ifdef PROTOTYPES
|
|
|
|
GLOBAL void
|
|
|
|
Log_ServerNotice(const char UserMode, const char *Format, ... )
|
|
|
|
#else
|
|
|
|
GLOBAL void
|
|
|
|
Log_ServerNotice(UserMode, Format, va_alist)
|
|
|
|
const char UserMode;
|
|
|
|
const char *Format;
|
|
|
|
va_dcl
|
|
|
|
#endif
|
2002-03-27 21:53:30 +01:00
|
|
|
{
|
|
|
|
CLIENT *c;
|
2010-05-22 17:10:22 +02:00
|
|
|
char msg[MAX_LOG_MSG_LEN];
|
|
|
|
va_list ap;
|
2002-03-27 21:53:30 +01:00
|
|
|
|
2010-05-22 17:10:22 +02:00
|
|
|
assert(Format != NULL);
|
2002-03-29 23:55:42 +01:00
|
|
|
|
2010-05-22 17:10:22 +02:00
|
|
|
#ifdef PROTOTYPES
|
|
|
|
va_start(ap, Format);
|
|
|
|
#else
|
|
|
|
va_start(ap);
|
|
|
|
#endif
|
|
|
|
vsnprintf(msg, MAX_LOG_MSG_LEN, Format, ap);
|
|
|
|
va_end(ap);
|
2005-08-29 12:58:00 +02:00
|
|
|
|
2010-05-22 17:10:22 +02:00
|
|
|
for(c=Client_First(); c != NULL; c=Client_Next(c)) {
|
|
|
|
if (Client_Conn(c) > NONE && Client_HasMode(c, UserMode))
|
|
|
|
IRC_WriteStrClient(c, "NOTICE %s :%s%s", Client_ID(c),
|
|
|
|
NOTICE_TXTPREFIX, msg);
|
2002-03-27 21:53:30 +01:00
|
|
|
}
|
2010-05-22 17:10:22 +02:00
|
|
|
} /* Log_ServerNotice */
|
2002-03-27 21:53:30 +01:00
|
|
|
|
|
|
|
|
2001-12-11 22:53:04 +01:00
|
|
|
/* -eof- */
|