From 9d239957bc6967324dfe6119eb19fd05bb783eba Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Wed, 20 Jan 2021 09:28:14 +0100 Subject: [PATCH] libc: update seek state on opening O_APPEND fds If a fd is opened in append mode and just is to be used (so never written by the parent component) for the to be forked child, the seek state was not pointing to the end of the file. The wrong seek value then was used in File_descriptor_allocator::generate_info(). Issue #3991 --- repos/libports/src/lib/libc/file_operations.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/repos/libports/src/lib/libc/file_operations.cc b/repos/libports/src/lib/libc/file_operations.cc index d385a60a58..b448e6fb07 100644 --- a/repos/libports/src/lib/libc/file_operations.cc +++ b/repos/libports/src/lib/libc/file_operations.cc @@ -555,6 +555,9 @@ __SYS_(int, open, (const char *pathname, int flags, ...), return -1; new_fdo->path(resolved_path.base()); + if (flags & O_APPEND) + lseek(new_fdo->libc_fd, 0, SEEK_END); + return new_fdo->libc_fd; })