From aad25fb00a95ab751c9744c69bd535f4931ca6fe Mon Sep 17 00:00:00 2001 From: Michael Ortmann Date: Fri, 13 Oct 2023 21:26:46 +0200 Subject: [PATCH] rip out log interval, switch logfile to line buffered, yeah, its posix 2001 --- doc/sphinx_source/tutorials/setup.rst | 2 +- doc/sphinx_source/using/core.rst | 7 ------ eggdrop.conf | 3 --- src/main.c | 16 +++--------- src/misc.c | 36 ++------------------------- src/proto.h | 1 - src/tcl.c | 2 -- 7 files changed, 6 insertions(+), 61 deletions(-) diff --git a/doc/sphinx_source/tutorials/setup.rst b/doc/sphinx_source/tutorials/setup.rst index f5ef4e162..31414cc9b 100644 --- a/doc/sphinx_source/tutorials/setup.rst +++ b/doc/sphinx_source/tutorials/setup.rst @@ -157,7 +157,7 @@ Now that your Eggdrop is on IRC and you've introduced yourself as owner, it's ti No show? ~~~~~~~~ -If your bot didn't appear on IRC, you should log in to the shell and view the bot's logfile (the default in the config file is "logs/eggdrop.log"). Note that logfile entries are not written to disk immediately unless quick-logs is enabled, so you may have to wait a few minutes before the logfile appears, or contains messages that indicate why your bot isn't showing up. +If your bot didn't appear on IRC, you should log in to the shell and view the bot's logfile (the default in the config file is "logs/eggdrop.log"). Additionally, you can kill the bot via the command line (``kill pid``, the pid is shown to you when you started the bot or can be viewed by running ``ps x``) and then restart it with the -mnt flag, which will launch you directly into the partyline, to assist with troubleshooting. Note that if you use the -nt flag, the bot will not persist and you will kill it once you quit the partyline. diff --git a/doc/sphinx_source/using/core.rst b/doc/sphinx_source/using/core.rst index 58a07193f..7e6883f2e 100644 --- a/doc/sphinx_source/using/core.rst +++ b/doc/sphinx_source/using/core.rst @@ -107,13 +107,6 @@ the logfile of the next day. reaches the size of 550 kilobytes. Note that this only works if you have keep-all-logs set to 0 (OFF). - set quick-logs 0 - This could be good if you have had a problem with logfiles filling - your quota/hard disk or if you log +p and publish it to the web, and - you need more up-to-date info. Note that this setting might increase - the CPU usage of your bot (on the other hand it will decrease your RAM - usage). - set raw-log 0 This setting allows you the logging of raw incoming server traffic via console/log flag 'r', raw outgoing server traffic via console/log mode diff --git a/eggdrop.conf b/eggdrop.conf index c9e058b78..16c5633d7 100755 --- a/eggdrop.conf +++ b/eggdrop.conf @@ -157,9 +157,6 @@ set max-logs 20 # have keep-all-logs 0 (OFF). set max-logsize 0 -# Interval between logfile saving operations in seconds. -set log-interval 15 - # This setting allows you the logging of raw incoming server traffic via # console/log flag 'r', raw outgoing server traffic via console/log mode 'v', # raw incoming botnet traffic via console/log mode 't', raw outgoing botnet diff --git a/src/main.c b/src/main.c index 9f256b367..df804b5b4 100644 --- a/src/main.c +++ b/src/main.c @@ -88,8 +88,7 @@ #endif extern char origbotname[], botnetnick[]; -extern int dcc_total, conmask, cache_hit, cache_miss, max_logs, log_interval, - quiet_save; +extern int dcc_total, conmask, cache_hit, cache_miss, max_logs, quiet_save; extern struct dcc_t *dcc; extern struct userrec *userlist; extern struct chanset_t *chanset; @@ -141,7 +140,6 @@ char ver[41]; /* Version info (short form) */ volatile sig_atomic_t do_restart = 0; /* .restart has been called, restart ASAP */ int resolve_timeout = RES_TIMEOUT; /* Hostname/address lookup timeout */ char quit_msg[1024]; /* Quit message */ -int log_elapsed = 1; /* Moved here for n flag warning, put back in do_arg if removed */ unsigned char cliflags = 0; @@ -188,7 +186,6 @@ void fatal(const char *s, int recoverable) int i; putlog(LOG_MISC, "*", "* %s", s); - flushlogs(); for (i = 0; i < dcc_total; i++) if (dcc[i].sock >= 0) killsock(dcc[i].sock); @@ -638,18 +635,10 @@ static void core_secondly() tell_mem_status_dcc(DP_STDOUT); } } - if (log_elapsed < log_interval) - log_elapsed++; - else { - flushlogs(); - check_logsize(); - log_elapsed = 1; - } nowmins = time(NULL) / 60; if (nowmins > lastmin) { memcpy(&nowtm, localtime(&now), sizeof(struct tm)); i = 0; - /* Once a minute */ ++lastmin; call_hook(HOOK_MINUTELY); @@ -670,6 +659,7 @@ static void core_secondly() if (((int) (nowtm.tm_min / 5) * 5) == (nowtm.tm_min)) { /* 5 min */ call_hook(HOOK_5MINUTELY); check_botnet_pings(); + if (!miltime) { /* At midnight */ char s[25]; int j; @@ -717,6 +707,7 @@ static void core_minutely() { check_tcl_time_and_cron(&nowtm); do_check_timers(&timer); + check_logsize(); } static void core_hourly() @@ -953,7 +944,6 @@ static void mainloop(int toplevel) putlog(LOG_MISC, "*", "%s", MOD_STAGNANT); } - flushlogs(); kill_tcl(); init_tcl(argc, argv); init_language(0); diff --git a/src/misc.c b/src/misc.c index 7016e1cb8..6019ad222 100644 --- a/src/misc.c +++ b/src/misc.c @@ -579,8 +579,10 @@ void putlog (int type, char *chname, const char *format, ...) if (keep_all_logs) { snprintf(path, sizeof path, "%s%s", logs[i].filename, ct); logs[i].f = fopen(path, "a"); + setvbuf(logs[i].f, NULL, _IOLBF, 0); /* line buffered */ } else logs[i].f = fopen(logs[i].filename, "a"); + setvbuf(logs[i].f, NULL, _IOLBF, 0); /* line buffered */ } if (logs[i].f != NULL) { /* Check if this is the same as the last line added to @@ -651,7 +653,6 @@ void logsuffix_change(char *s) } for (i = 0; i < max_logs; i++) { if (logs[i].f) { - fflush(logs[i].f); fclose(logs[i].f); logs[i].f = NULL; } @@ -676,7 +677,6 @@ void check_logsize() if (logs[i].f) { /* write to the log before closing it huh.. */ putlog(LOG_MISC, "*", MISC_CLOGS, logs[i].filename, ss.st_size); - fflush(logs[i].f); fclose(logs[i].f); logs[i].f = NULL; } @@ -691,38 +691,6 @@ void check_logsize() } } -/* Flush the logfiles to disk - */ -void flushlogs() -{ - int i; - - /* Logs may not be initialised yet. */ - if (!logs) - return; - - /* Now also checks to see if there's a repeat message and - * displays the 'last message repeated...' stuff too - */ - for (i = 0; i < max_logs; i++) { - if (logs[i].f != NULL) { - if (logs[i].repeats > 0) { - /* Repeat.. display 'last message repeated x times' and reset repeats. - */ - char stamp[33]; - - strftime(stamp, sizeof(stamp) - 1, log_ts, localtime(&now)); - fprintf(logs[i].f, "%s ", stamp); - fprintf(logs[i].f, MISC_LOGREPEAT, logs[i].repeats); - /* Reset repeats */ - logs[i].repeats = 0; - } - fflush(logs[i].f); - } - } -} - - /* * String substitution functions */ diff --git a/src/proto.h b/src/proto.h index 63cfc574c..abe8af9b7 100644 --- a/src/proto.h +++ b/src/proto.h @@ -228,7 +228,6 @@ void debug_mem_to_dcc(int); int egg_strcatn(char *, const char *, size_t); int my_strcpy(char *, char *); void putlog(int type, char *chname, const char *format, ...) ATTRIBUTE_FORMAT(printf,3,4); -void flushlogs(void); void check_logsize(void); void splitc(char *, char *, char); void splitcn(char *, char *, char, size_t); diff --git a/src/tcl.c b/src/tcl.c index 6ea16befd..cf80d977c 100644 --- a/src/tcl.c +++ b/src/tcl.c @@ -88,7 +88,6 @@ int must_be_owner = 1; int quiet_reject = 1; int copy_to_tmp = 1; int max_socks = 100; -int log_interval = 15; int par_telnet_flood = 1; int quiet_save = 0; int strtot = 0; @@ -481,7 +480,6 @@ static tcl_ints def_tcl_ints[] = { {"max-socks", &max_socks, 0}, {"max-logs", &max_logs, 0}, {"max-logsize", &max_logsize, 0}, - {"log-interval", &log_interval, 0}, {"raw-log", &raw_log, 1}, {"protect-telnet", &protect_telnet, 0}, {"dcc-sanitycheck", &dcc_sanitycheck, 0},