1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-06-25 06:56:39 +02:00

log { } now uses the new log system and is used for logging to disk,

snomasks, opers, global (remote), ..

For disk logs we currently ignore the sources and log everything.

NOTE: REHASH is untested and will memory leak for sure.
This commit is contained in:
Bram Matthys
2021-08-07 13:02:56 +02:00
parent b8837844fb
commit e59cd278cd
4 changed files with 76 additions and 177 deletions
+1 -1
View File
@@ -67,7 +67,7 @@ typedef enum BanTarget { BAN_TARGET_IP=1, BAN_TARGET_USERIP=2, BAN_TARGET_HOST=3
typedef enum HideIdleTimePolicy { HIDE_IDLE_TIME_NEVER=1, HIDE_IDLE_TIME_ALWAYS=2, HIDE_IDLE_TIME_USERMODE=3, HIDE_IDLE_TIME_OPER_USERMODE=4 } HideIdleTimePolicy;
typedef enum LogDestination { LOG_DEST_SNOMASK=0, LOG_DEST_OPER=1, LOG_DEST_GLOBAL=2, LOG_DEST_CHANNEL=3, LOG_DEST_DISK=4 } LogDestination;
typedef enum LogDestination { LOG_DEST_SNOMASK=0, LOG_DEST_OPER=1, LOG_DEST_GLOBAL=2, LOG_DEST_CHANNEL=3, LOG_DEST_OTHER=4 } LogDestination;
/** The set { } block configuration */
typedef struct Configuration Configuration;
+6 -1
View File
@@ -274,8 +274,13 @@ struct LogSource {
typedef struct Log Log;
struct Log {
Log *prev, *next;
char destination[CHANNELLEN+1];
LogSource *sources;
char destination[CHANNELLEN+1];
char *file;
char *filefmt;
long maxsize;
int type;
int logfd;
};
/*
+3 -21
View File
@@ -123,7 +123,6 @@ static ConfigCommand _ConfigCommands[] = {
{ "listen", _conf_listen, _test_listen },
{ "loadmodule", NULL, _test_loadmodule},
{ "log", config_run_log, config_test_log },
{ "logx", config_run_logx, config_test_logx },
{ "me", _conf_me, _test_me },
{ "official-channels", _conf_offchans, _test_offchans },
{ "oper", _conf_oper, _test_oper },
@@ -238,7 +237,8 @@ ConfigItem_deny_channel *conf_deny_channel = NULL;
ConfigItem_allow_channel *conf_allow_channel = NULL;
ConfigItem_deny_link *conf_deny_link = NULL;
ConfigItem_deny_version *conf_deny_version = NULL;
ConfigItem_log *conf_log = NULL;
Log *logs[5] = { NULL, NULL, NULL, NULL, NULL };
Log *temp_logs[5] = { NULL, NULL, NULL, NULL, NULL };
ConfigItem_alias *conf_alias = NULL;
ConfigItem_include *conf_include = NULL;
ConfigItem_blacklist_module *conf_blacklist_module = NULL;
@@ -1865,16 +1865,7 @@ void config_setdefaultsettings(Configuration *i)
static void make_default_logblock(void)
{
ConfigItem_log *ca = safe_alloc(sizeof(ConfigItem_log));
config_status("No log { } block found -- logging everything to 'ircd.log'");
safe_strdup(ca->file, "ircd.log");
convert_to_absolute_path(&ca->file, LOGDIR);
ca->flags |= LOG_CHGCMDS|LOG_CLIENT|LOG_ERROR|LOG_KILL|LOG_KLINE|LOG_OPER|LOG_OVERRIDE|LOG_SACMDS|LOG_SERVER|LOG_SPAMFILTER|LOG_TKL;
ca->type = LOG_TYPE_TEXT;
ca->logfd = -1;
AddListItem(ca, conf_log);
// FIXME: move or don't move :)
}
/** Similar to config_setdefaultsettings but this one is applied *AFTER*
@@ -2467,7 +2458,6 @@ void config_rehash()
ConfigItem_allow_channel *allow_channel_ptr;
ConfigItem_admin *admin_ptr;
ConfigItem_deny_version *deny_version_ptr;
ConfigItem_log *log_ptr;
ConfigItem_alias *alias_ptr;
ConfigItem_help *help_ptr;
ConfigItem_offchans *of_ptr;
@@ -2658,14 +2648,6 @@ void config_rehash()
conf_drpass->dieauth = NULL;
safe_free(conf_drpass);
}
for (log_ptr = conf_log; log_ptr; log_ptr = (ConfigItem_log *)next) {
next = (ListStruct *)log_ptr->next;
if (log_ptr->logfd != -1)
fd_close(log_ptr->logfd);
safe_free(log_ptr->file);
DelListItem(log_ptr, conf_log);
safe_free(log_ptr);
}
for (alias_ptr = conf_alias; alias_ptr; alias_ptr = (ConfigItem_alias *)next) {
RealCommand *cmptr = find_command(alias_ptr->alias, 0);
ConfigItem_alias_format *fmt;
+66 -154
View File
@@ -75,152 +75,6 @@ char *log_type_valtostring(LogType v)
/***** CONFIGURATION ******/
int config_test_log(ConfigFile *conf, ConfigEntry *ce)
{
int fd, errors = 0;
ConfigEntry *cep, *cepp;
char has_flags = 0, has_maxsize = 0;
char *fname;
if (!ce->value)
{
config_error("%s:%i: log block without filename",
ce->file->filename, ce->line_number);
return 1;
}
if (!ce->items)
{
config_error("%s:%i: empty log block",
ce->file->filename, ce->line_number);
return 1;
}
/* Convert to absolute path (if needed) unless it's "syslog" */
if (strcmp(ce->value, "syslog"))
convert_to_absolute_path(&ce->value, LOGDIR);
for (cep = ce->items; cep; cep = cep->next)
{
if (!strcmp(cep->name, "flags"))
{
if (has_flags)
{
config_warn_duplicate(cep->file->filename,
cep->line_number, "log::flags");
continue;
}
has_flags = 1;
if (!cep->items)
{
config_error_empty(cep->file->filename,
cep->line_number, "log", cep->name);
errors++;
continue;
}
for (cepp = cep->items; cepp; cepp = cepp->next)
{
// FIXME: old flags shit
}
}
else if (!strcmp(cep->name, "maxsize"))
{
if (has_maxsize)
{
config_warn_duplicate(cep->file->filename,
cep->line_number, "log::maxsize");
continue;
}
has_maxsize = 1;
if (!cep->value)
{
config_error_empty(cep->file->filename,
cep->line_number, "log", cep->name);
errors++;
}
}
else if (!strcmp(cep->name, "type"))
{
if (!cep->value)
{
config_error_empty(cep->file->filename,
cep->line_number, "log", cep->name);
errors++;
continue;
}
if (!log_type_stringtoval(cep->value))
{
config_error("%s:%i: unknown log type '%s'",
cep->file->filename, cep->line_number,
cep->value);
errors++;
}
}
else
{
config_error_unknown(cep->file->filename, cep->line_number,
"log", cep->name);
errors++;
continue;
}
}
if (!has_flags)
{
config_error_missing(ce->file->filename, ce->line_number,
"log::flags");
errors++;
}
fname = unreal_strftime(ce->value);
if ((fd = fd_fileopen(fname, O_WRONLY|O_CREAT)) == -1)
{
config_error("%s:%i: Couldn't open logfile (%s) for writing: %s",
ce->file->filename, ce->line_number,
fname, strerror(errno));
errors++;
} else
{
fd_close(fd);
}
return errors;
}
int config_run_log(ConfigFile *conf, ConfigEntry *ce)
{
ConfigEntry *cep, *cepp;
ConfigItem_log *ca;
ca = safe_alloc(sizeof(ConfigItem_log));
ca->logfd = -1;
ca->type = LOG_TYPE_TEXT; /* default */
if (strchr(ce->value, '%'))
safe_strdup(ca->filefmt, ce->value);
else
safe_strdup(ca->file, ce->value);
for (cep = ce->items; cep; cep = cep->next)
{
if (!strcmp(cep->name, "maxsize"))
{
ca->maxsize = config_checkval(cep->value,CFG_SIZE);
}
else if (!strcmp(cep->name, "type"))
{
ca->type = log_type_stringtoval(cep->value);
}
else if (!strcmp(cep->name, "flags"))
{
for (cepp = cep->items; cepp; cepp = cepp->next)
{
// FIXME: old flags shit
}
}
}
AddListItem(ca, conf_log);
return 1;
}
LogSource *add_log_source(const char *str)
{
LogSource *ls;
@@ -267,11 +121,11 @@ LogSource *add_log_source(const char *str)
return ls;
}
int config_test_logx(ConfigFile *conf, ConfigEntry *block)
int config_test_log(ConfigFile *conf, ConfigEntry *block)
{
int errors = 0;
int any_sources = 0;
ConfigEntry *ce, *cep;
ConfigEntry *ce, *cep, *cepp;
int destinations = 0;
for (ce = block->items; ce; ce = ce->next)
@@ -333,11 +187,45 @@ int config_test_logx(ConfigFile *conf, ConfigEntry *block)
errors++;
continue;
}
convert_to_absolute_path(&cep->value, LOGDIR);
for (cepp = cep->items; cepp; cepp = cepp->next)
{
if (!strcmp(cepp->name, "type"))
{
if (!cepp->value)
{
config_error_empty(cepp->file->filename,
cepp->line_number, "log", cepp->name);
errors++;
continue;
}
if (!log_type_stringtoval(cepp->value))
{
config_error("%s:%i: unknown log type '%s'",
cepp->file->filename, cepp->line_number,
cepp->value);
errors++;
}
} else
if (!strcmp(cepp->name, "maxsize"))
{
if (!cepp->value)
{
config_error_empty(cepp->file->filename,
cepp->line_number, "log", cepp->name);
errors++;
}
} else
{
config_error_unknown(cepp->file->filename, cepp->line_number, "log::destination::file", cepp->name);
errors++;
}
}
} else
if (!strcmp(cep->name, "global"))
{
destinations++;
} else
} else // TODO: re-add syslog support too
{
config_error_unknownopt(cep->file->filename, cep->line_number, "log::destination", cep->name);
errors++;
@@ -368,9 +256,9 @@ int config_test_logx(ConfigFile *conf, ConfigEntry *block)
return errors;
}
int config_run_logx(ConfigFile *conf, ConfigEntry *block)
int config_run_log(ConfigFile *conf, ConfigEntry *block)
{
ConfigEntry *ce, *cep;
ConfigEntry *ce, *cep, *cepp;
LogSource *sources = NULL;
Log *log = safe_alloc(sizeof(Log));
int type;
@@ -401,6 +289,7 @@ int config_run_logx(ConfigFile *conf, ConfigEntry *block)
{
if (!strcmp(cep->name, "snomask"))
{
Log *log = safe_alloc(sizeof(Log));
strlcpy(log->destination, cep->value, sizeof(log->destination)); /* destination is the snomask */
log->sources = sources;
if (!strcmp(cep->value, "all"))
@@ -417,10 +306,33 @@ int config_run_logx(ConfigFile *conf, ConfigEntry *block)
} else
if (!strcmp(cep->name, "global"))
{
Log *d = safe_alloc(sizeof(Log));
Log *log = safe_alloc(sizeof(Log));
/* destination stays empty */
log->sources = sources;
AddListItem(log, tempiConf.logs[LOG_DEST_GLOBAL]);
} else
if (!strcmp(cep->name, "file"))
{
Log *log = safe_alloc(sizeof(Log));
log->sources = sources;
log->logfd = -1;
log->type = LOG_TYPE_TEXT; /* default */
if (strchr(cep->value, '%'))
safe_strdup(log->filefmt, cep->value);
else
safe_strdup(log->file, cep->value);
for (cepp = cep->items; cepp; cepp = cepp->next)
{
if (!strcmp(cepp->name, "maxsize"))
{
log->maxsize = config_checkval(cepp->value,CFG_SIZE);
}
else if (!strcmp(cepp->name, "type"))
{
log->type = log_type_stringtoval(cepp->value);
}
}
AddListItem(log, tempiConf.logs[LOG_DEST_OTHER]);
}
}
}
@@ -985,7 +897,7 @@ literal:
void do_unreal_log_disk(LogLevel loglevel, char *subsystem, char *event_id, char *msg, char *json_serialized)
{
static int last_log_file_warning = 0;
ConfigItem_log *l;
Log *l;
char text_buf[2048], timebuf[128];
struct stat fstats;
int n;
@@ -1011,7 +923,7 @@ void do_unreal_log_disk(LogLevel loglevel, char *subsystem, char *event_id, char
if (loop.config_test)
return;
for (l = conf_log; l; l = l->next)
for (l = iConf.logs[LOG_DEST_OTHER]; l; l = l->next)
{
// FIXME: implement the proper log filters (eg what 'flags' previously was)
//if (!(l->flags & flags))