summaryrefslogtreecommitdiff
path: root/sysklogd
diff options
context:
space:
mode:
authorJoshua Judson Rosen2014-05-20 01:02:20 -0400
committerDenys Vlasenko2014-06-02 03:11:40 +0200
commit9aa6ffb22b712d4e928604e291f954b02237e8cd (patch)
treead606fe29c75f2acfdad5c2b328d56f911c3047e /sysklogd
parentb905d6c2eaaf7ad92a50dccc7b91ee19dd9424b7 (diff)
downloadbusybox-9aa6ffb22b712d4e928604e291f954b02237e8cd.zip
busybox-9aa6ffb22b712d4e928604e291f954b02237e8cd.tar.gz
syslogd: Unify unlink/truncate + unlock log-rotation logic
Always unlink + reopen, rather than sometimes using ftruncate(); using a single code-path reduces the opportunity for either mistakes or duplicate code. Signed-off-by: Joshua Judson Rosen <jrosen@harvestai.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'sysklogd')
-rw-r--r--sysklogd/syslogd.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index d77fc94..f758510 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -648,32 +648,24 @@ static void log_locally(time_t now, char *msg, logFile_t *log_file)
}
/* newFile == "f.0" now */
rename(log_file->path, newFile);
- /* Incredibly, if F and F.0 are hardlinks, POSIX
- * _demands_ that rename returns 0 but does not
- * remove F!!!
- * (hardlinked F/F.0 pair was observed after
- * power failure during rename()).
- * Ensure old file is gone:
- */
- unlink(log_file->path);
-#ifdef SYSLOGD_WRLOCK
- fl.l_type = F_UNLCK;
- fcntl(log_file->fd, F_SETLKW, &fl);
-#endif
- close(log_file->fd);
- goto reopen;
}
- /* We don't get here unless G.logFileRotate == 0;
- * in which case don't bother unlinking and reopening,
- * just truncate and reset size to match:
+ /* We may or may not have just renamed the file away;
+ * if we didn't rename because we aren't keeping any backlog,
+ * then it's time to clobber the file. If we did rename it...,
+ * incredibly, if F and F.0 are hardlinks, POSIX _demands_
+ * that rename returns 0 but does not remove F!!!
+ * (hardlinked F/F.0 pair was observed after
+ * power failure during rename()).
+ * So ensure old file is gone in any case:
*/
- ftruncate(log_file->fd, 0);
- log_file->size = 0;
+ unlink(log_file->path);
#ifdef SYSLOGD_WRLOCK
fl.l_type = F_UNLCK;
fcntl(log_file->fd, F_SETLKW, &fl);
#endif
+ close(log_file->fd);
+ goto reopen;
}
log_file->size +=
#endif