From 658fb9b0374bb603e7b0ae04e30f62a5984965c0 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Tue, 23 Jan 2018 11:39:50 +0100 Subject: [PATCH] Check return value from rename(), fall back to truncate() on error Signed-off-by: Joachim Nilsson --- src/logit.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/logit.c b/src/logit.c index 4a90a700..c8b9787b 100644 --- a/src/logit.c +++ b/src/logit.c @@ -86,8 +86,10 @@ static int logrotate(char *file, int num, off_t sz) } } - rename(file, nfile); - create(file, st.st_mode, st.st_uid, st.st_gid); + if (rename(file, nfile)) + (void)truncate(file, 0); + else + create(file, st.st_mode, st.st_uid, st.st_gid); } else { if (truncate(file, 0)) syslog(LOG_ERR | LOG_PERROR, "Failed truncating %s during logrotate: %s", file, strerror(errno));