Check return value from rename(), fall back to truncate() on error

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2018-01-23 11:39:50 +01:00
parent a84bb9042f
commit 658fb9b037
+4 -2
View File
@@ -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));