diff options
author | Joshua Judson Rosen <jrosen@harvestai.com> | 2014-07-03 14:51:47 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-07-03 14:51:47 +0200 |
commit | ae57fcad5d36dc2ba00179ef3e44154c10223862 (patch) | |
tree | 03eea81e4c4c8e3944327ae46fe15c4939846fd4 | |
parent | e46047aa87c9ec0b8e27d1d4ecfcb3e9798ddb8d (diff) | |
download | busybox-w32-ae57fcad5d36dc2ba00179ef3e44154c10223862.tar.gz busybox-w32-ae57fcad5d36dc2ba00179ef3e44154c10223862.tar.bz2 busybox-w32-ae57fcad5d36dc2ba00179ef3e44154c10223862.zip |
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.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 04221fc33..266657f3b 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -110,6 +110,7 @@ typedef struct { | |||
110 | typedef struct logFile_t { | 110 | typedef struct logFile_t { |
111 | const char *path; | 111 | const char *path; |
112 | int fd; | 112 | int fd; |
113 | time_t last_log_time; | ||
113 | #if ENABLE_FEATURE_ROTATE_LOGFILE | 114 | #if ENABLE_FEATURE_ROTATE_LOGFILE |
114 | unsigned size; | 115 | unsigned size; |
115 | uint8_t isRegular; | 116 | uint8_t isRegular; |
@@ -165,7 +166,6 @@ struct globals { | |||
165 | #if ENABLE_FEATURE_IPC_SYSLOG | 166 | #if ENABLE_FEATURE_IPC_SYSLOG |
166 | struct shbuf_ds *shbuf; | 167 | struct shbuf_ds *shbuf; |
167 | #endif | 168 | #endif |
168 | time_t last_log_time; | ||
169 | /* localhost's name. We print only first 64 chars */ | 169 | /* localhost's name. We print only first 64 chars */ |
170 | char *hostname; | 170 | char *hostname; |
171 | 171 | ||
@@ -588,15 +588,16 @@ static void log_locally(time_t now, char *msg, logFile_t *log_file) | |||
588 | /* fd can't be 0 (we connect fd 0 to /dev/log socket) */ | 588 | /* fd can't be 0 (we connect fd 0 to /dev/log socket) */ |
589 | /* fd is 1 if "-O -" is in use */ | 589 | /* fd is 1 if "-O -" is in use */ |
590 | if (log_file->fd > 1) { | 590 | if (log_file->fd > 1) { |
591 | /* Reopen log file every second. This allows admin | 591 | /* Reopen log files every second. This allows admin |
592 | * to delete the file and not worry about restarting us. | 592 | * to delete the files and not worry about restarting us. |
593 | * This costs almost nothing since it happens | 593 | * This costs almost nothing since it happens |
594 | * _at most_ once a second. | 594 | * _at most_ once a second for each file, and happens |
595 | * only when each file is actually written. | ||
595 | */ | 596 | */ |
596 | if (!now) | 597 | if (!now) |
597 | now = time(NULL); | 598 | now = time(NULL); |
598 | if (G.last_log_time != now) { | 599 | if (log_file->last_log_time != now) { |
599 | G.last_log_time = now; | 600 | log_file->last_log_time = now; |
600 | close(log_file->fd); | 601 | close(log_file->fd); |
601 | goto reopen; | 602 | goto reopen; |
602 | } | 603 | } |