diff --git a/repos/libports/include/libc-plugin/fd_alloc.h b/repos/libports/include/libc-plugin/fd_alloc.h index 33bbcec2fe..4be81b0917 100644 --- a/repos/libports/include/libc-plugin/fd_alloc.h +++ b/repos/libports/include/libc-plugin/fd_alloc.h @@ -113,6 +113,11 @@ namespace Libc { */ File_descriptor *any_cloexec_libc_fd(); + /** + * Update seek state of file descriptor with append flag set. + */ + void update_append_libc_fds(); + /** * Return file-descriptor ID of any open file, or -1 if no file is * open diff --git a/repos/libports/src/lib/libc/fd_alloc.cc b/repos/libports/src/lib/libc/fd_alloc.cc index e6fb4d83da..39de362201 100644 --- a/repos/libports/src/lib/libc/fd_alloc.cc +++ b/repos/libports/src/lib/libc/fd_alloc.cc @@ -127,6 +127,17 @@ File_descriptor *File_descriptor_allocator::any_cloexec_libc_fd() } +void File_descriptor_allocator::update_append_libc_fds() +{ + Mutex::Guard guard(_mutex); + + _id_space.for_each([&] (File_descriptor &fd) { + if (fd.flags & O_APPEND) + fd.plugin->lseek(&fd, 0, SEEK_END); + }); +} + + int File_descriptor_allocator::any_open_fd() { Mutex::Guard guard(_mutex); diff --git a/repos/libports/src/lib/libc/fork.cc b/repos/libports/src/lib/libc/fork.cc index e4f0c7fb5a..eb434659b5 100644 --- a/repos/libports/src/lib/libc/fork.cc +++ b/repos/libports/src/lib/libc/fork.cc @@ -721,6 +721,8 @@ extern "C" pid_t __sys_wait4(pid_t pid, int *status, int options, rusage *rusage return Fn::INCOMPLETE; }); + file_descriptor_allocator()->update_append_libc_fds(); + /* * The libc expects status information in bits 0..6 and the exit value * in bits 8..15 (according to 'wait.h').