diff --git a/Changes b/Changes index fdf58d7f1..8e8cb0980 100644 --- a/Changes +++ b/Changes @@ -770,3 +770,4 @@ seen. gmtime warning still there - Fixed a win32 bug where /restart didn't remove the tray icon, reported by PHANTOm and Gilou - Fixed Osiris's example.conf - Fixed IPv6 bindip error found by Madkiss +- Added log::maxsize, when this size is reached the log is cleared and started over again diff --git a/include/struct.h b/include/struct.h index 6cde711f5..f581f90ac 100644 --- a/include/struct.h +++ b/include/struct.h @@ -1023,6 +1023,7 @@ struct _configitem_log { ConfigFlag flag; ConfigItem *prev, *next; char *file; + long maxsize; int flags; }; diff --git a/src/s_conf.c b/src/s_conf.c index dea5b871c..dcbc715b6 100644 --- a/src/s_conf.c +++ b/src/s_conf.c @@ -2627,6 +2627,8 @@ int _conf_log(ConfigFile *conf, ConfigEntry *ce) cep->ce_varlinenum); continue; } + if (!strcmp(cep->ce_varname, "maxsize")) + log->maxsize = atol(cep->ce_vardata); if (!strcmp(cep->ce_varname, "flags")) { for (cepp = cep->ce_entries; cepp; cepp = cepp->ce_next) { diff --git a/src/s_extra.c b/src/s_extra.c index d30fdabdc..b362aac49 100644 --- a/src/s_extra.c +++ b/src/s_extra.c @@ -426,12 +426,25 @@ void ircd_log(int flags, char *format, ...) ConfigItem_log *logs; char buf[2048], timebuf[128]; int fd; + struct stat fstats; va_start(ap, format); ircvsprintf(buf, format, ap); strcat(buf, "\n"); sprintf(timebuf, "[%s] - ", myctime(TStime())); for (logs = conf_log; logs; logs = (ConfigItem_log *) logs->next) { if (logs->flags & flags) { + stat(logs->file, &fstats); + if (logs->maxsize && fstats.st_size >= logs->maxsize) { +#ifndef _WIN32 + fd = open(logs->file, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR); +#else + fd = open(logs->file, O_CREAT|O_WRONLY|O_TRUNC); +#endif + if (fd == -1) + continue; + write(fd, "Max file size reached, starting new log file\n", 46); + } + else { #ifndef _WIN32 fd = open(logs->file, O_CREAT|O_APPEND|O_WRONLY, S_IRUSR|S_IWUSR); #else @@ -439,6 +452,7 @@ void ircd_log(int flags, char *format, ...) #endif if (fd == -1) continue; + } write(fd, timebuf, strlen(timebuf)); write(fd, buf, strlen(buf)); close(fd);