mirror of
https://github.com/unrealircd/unrealircd.git
synced 2026-07-03 16:03:12 +02:00
- Changed logging into not open/close constantly, #0002943. This may leaks
fds and cause problems, so its a heads up
This commit is contained in:
@@ -1807,3 +1807,5 @@ MOTDs
|
||||
onlymodules = only build m_* modules (plus chanmodes)
|
||||
commandsandmodules = build both. We still need to add this as a default or
|
||||
a ./Config option. Default is commandsandmodules. Any takers?
|
||||
- Changed logging into not open/close constantly, #0002943. This may leaks
|
||||
fds and cause problems, so its a heads up
|
||||
|
||||
@@ -1314,6 +1314,7 @@ struct _configitem_log {
|
||||
char *file;
|
||||
long maxsize;
|
||||
int flags;
|
||||
int logfd;
|
||||
};
|
||||
|
||||
struct _configitem_unknown {
|
||||
|
||||
+4
-1
@@ -1406,6 +1406,7 @@ ConfigItem_log *ca = MyMallocEx(sizeof(ConfigItem_log));
|
||||
config_status("No log { } block found -- using default: errors will be logged to 'ircd.log'");
|
||||
|
||||
ca->file = strdup("ircd.log");
|
||||
ca->logfd = -1;
|
||||
ca->flags |= LOG_ERROR;
|
||||
AddListItem(ca, conf_log);
|
||||
}
|
||||
@@ -1917,6 +1918,8 @@ void config_rehash()
|
||||
}
|
||||
for (log_ptr = conf_log; log_ptr; log_ptr = (ConfigItem_log *)next) {
|
||||
next = (ListStruct *)log_ptr->next;
|
||||
if (log_ptr->logfd != -1)
|
||||
close(log_ptr->logfd);
|
||||
ircfree(log_ptr->file);
|
||||
DelListItem(log_ptr, conf_log);
|
||||
MyFree(log_ptr);
|
||||
@@ -5632,7 +5635,7 @@ int _conf_log(ConfigFile *conf, ConfigEntry *ce)
|
||||
|
||||
ca = MyMallocEx(sizeof(ConfigItem_log));
|
||||
ircstrdup(ca->file, ce->ce_vardata);
|
||||
|
||||
ca->logfd = -1;
|
||||
for (cep = ce->ce_entries; cep; cep = cep->ce_next)
|
||||
{
|
||||
if (!strcmp(cep->ce_varname, "maxsize"))
|
||||
|
||||
+19
-13
@@ -285,7 +285,6 @@ void ircd_log(int flags, char *format, ...)
|
||||
va_list ap;
|
||||
ConfigItem_log *logs;
|
||||
char buf[2048], timebuf[128];
|
||||
int fd;
|
||||
struct stat fstats;
|
||||
|
||||
va_start(ap, format);
|
||||
@@ -308,27 +307,34 @@ void ircd_log(int flags, char *format, ...)
|
||||
#endif
|
||||
if (logs->flags & flags) {
|
||||
if (stat(logs->file, &fstats) != -1 && logs->maxsize && fstats.st_size >= logs->maxsize) {
|
||||
if (logs->logfd != -1)
|
||||
close(logs->logfd);
|
||||
#ifndef _WIN32
|
||||
fd = open(logs->file, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
|
||||
logs->logfd = open(logs->file, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
|
||||
#else
|
||||
fd = open(logs->file, O_CREAT|O_WRONLY|O_TRUNC, S_IREAD|S_IWRITE);
|
||||
logs->logfd = open(logs->file, O_CREAT|O_WRONLY|O_TRUNC, S_IREAD|S_IWRITE);
|
||||
#endif
|
||||
if (fd == -1)
|
||||
if (logs->logfd == -1)
|
||||
continue;
|
||||
write(fd, "Max file size reached, starting new log file\n", 45);
|
||||
write(logs->logfd, "Max file size reached, starting new log file\n", 45);
|
||||
}
|
||||
else {
|
||||
if (logs->logfd == -1)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
fd = open(logs->file, O_CREAT|O_APPEND|O_WRONLY, S_IRUSR|S_IWUSR);
|
||||
logs->logfd = open(logs->file, O_CREAT|O_APPEND|O_WRONLY, S_IRUSR|S_IWUSR);
|
||||
#else
|
||||
fd = open(logs->file, O_CREAT|O_APPEND|O_WRONLY, S_IREAD|S_IWRITE);
|
||||
logs->logfd = open(logs->file, O_CREAT|O_APPEND|O_WRONLY, S_IREAD|S_IWRITE);
|
||||
#endif
|
||||
}
|
||||
if (logs->logfd == -1)
|
||||
continue;
|
||||
}
|
||||
write(logs->logfd, timebuf, strlen(timebuf));
|
||||
write(logs->logfd, buf, strlen(buf));
|
||||
#ifndef _WIN32
|
||||
fsync(logs->logfd);
|
||||
#endif
|
||||
if (fd == -1)
|
||||
continue;
|
||||
}
|
||||
write(fd, timebuf, strlen(timebuf));
|
||||
write(fd, buf, strlen(buf));
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
Reference in New Issue
Block a user