summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Judson Rosen2014-07-03 14:51:47 +0200
committerDenys Vlasenko2014-07-03 14:51:47 +0200
commitae57fcad5d36dc2ba00179ef3e44154c10223862 (patch)
tree03eea81e4c4c8e3944327ae46fe15c4939846fd4
parente46047aa87c9ec0b8e27d1d4ecfcb3e9798ddb8d (diff)
downloadbusybox-ae57fcad5d36dc2ba00179ef3e44154c10223862.zip
busybox-ae57fcad5d36dc2ba00179ef3e44154c10223862.tar.gz
syslogd: make "reopen log file every second" logic work for multiple logs
Move last_log_time from a single global to *each logFile_t* so that we can actually apply the logic to every log-file in multi-file configurations, rather than working only for the first file written in each 1-second interval and then leaving the others connected to possibly wrong files. Signed-off-by: Joshua Judson Rosen <jrosen@harvestai.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--sysklogd/syslogd.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index 04221fc..266657f 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -110,6 +110,7 @@ typedef struct {
typedef struct logFile_t {
const char *path;
int fd;
+ time_t last_log_time;
#if ENABLE_FEATURE_ROTATE_LOGFILE
unsigned size;
uint8_t isRegular;
@@ -165,7 +166,6 @@ struct globals {
#if ENABLE_FEATURE_IPC_SYSLOG
struct shbuf_ds *shbuf;
#endif
- time_t last_log_time;
/* localhost's name. We print only first 64 chars */
char *hostname;
@@ -588,15 +588,16 @@ static void log_locally(time_t now, char *msg, logFile_t *log_file)
/* fd can't be 0 (we connect fd 0 to /dev/log socket) */
/* fd is 1 if "-O -" is in use */
if (log_file->fd > 1) {
- /* Reopen log file every second. This allows admin
- * to delete the file and not worry about restarting us.
+ /* Reopen log files every second. This allows admin
+ * to delete the files and not worry about restarting us.
* This costs almost nothing since it happens
- * _at most_ once a second.
+ * _at most_ once a second for each file, and happens
+ * only when each file is actually written.
*/
if (!now)
now = time(NULL);
- if (G.last_log_time != now) {
- G.last_log_time = now;
+ if (log_file->last_log_time != now) {
+ log_file->last_log_time = now;
close(log_file->fd);
goto reopen;
}