We open the log file with O_APPEND, but switch it off before seeking, and turn it back on afterwards. We never seek when O_APPEND is on, so we don't actually need it, as its only function is to override the offset for writes so that they are always performed at the end regardless of the current offset (which is at the end anyway, for us). Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com> --- log.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/log.c b/log.c index 6932885..dd25862 100644 --- a/log.c +++ b/log.c @@ -204,9 +204,6 @@ out: */ static int logfile_rotate(int fd, const struct timespec *now) { - if (fcntl(fd, F_SETFL, O_RDWR /* Drop O_APPEND: explicit lseek() */)) - return -errno; - #ifdef FALLOC_FL_COLLAPSE_RANGE /* Only for Linux >= 3.15, extent-based ext4 or XFS, glibc >= 2.18 */ if (!fallocate(fd, FALLOC_FL_COLLAPSE_RANGE, 0, log_cut_size)) @@ -215,9 +212,6 @@ static int logfile_rotate(int fd, const struct timespec *now) #endif logfile_rotate_move(fd, now); - if (fcntl(fd, F_SETFL, O_RDWR | O_APPEND)) - return -errno; - return 0; } @@ -416,7 +410,7 @@ void logfile_init(const char *name, const char *path, size_t size) if (readlink("/proc/self/exe", exe, PATH_MAX - 1) < 0) die_perror("Failed to read own /proc/self/exe link"); - log_file = open(path, O_CREAT | O_TRUNC | O_APPEND | O_RDWR | O_CLOEXEC, + log_file = open(path, O_CREAT | O_TRUNC | O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR); if (log_file == -1) die_perror("Couldn't open log file %s", path); -- 2.43.0