libc: update O_APPEND fds on joined child

The fds in O_APPEND state may have changed by the child. The local seek
state needs to be valid/current for the next to be forked child, which seek
state is set by File_descriptor_allocator::generate_info().

Issue #3991
This commit is contained in:
Alexander Boettcher 2021-01-20 09:16:27 +01:00 committed by Norman Feske
parent 9bfd812a88
commit 5fa91c573b
3 changed files with 18 additions and 0 deletions

View File

@ -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

View File

@ -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>([&] (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);

View File

@ -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').