1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 18:28:10 +00:00

Kernel: Move setting file flags and r/w mode to VFS::open()

Previously, VFS::open() would only use the passed flags for permission checking
purposes, and Process::sys$open() would set them on the created FileDescription
explicitly. Now, they should be set by VFS::open() on any files being opened,
including files that the kernel opens internally.

This also lets us get rid of the explicit check for whether or not the returned
FileDescription was a preopen fd, and in fact, fixes a bug where a read-only
preopen fd without any other flags would be considered freshly opened (due to
O_RDONLY being indistinguishable from 0) and granted a new set of flags.
This commit is contained in:
Sergey Bugaev 2020-01-19 01:15:52 +03:00 committed by Andreas Kling
parent 544b8286da
commit d0d13e2bf5
4 changed files with 10 additions and 12 deletions

View file

@ -1971,14 +1971,6 @@ int Process::sys$open(const Syscall::SC_open_params* user_params)
if (result.is_error())
return result.error();
auto description = result.value();
if (description->file_flags()) {
// We already have file flags set on this description, so
// it must be a preopen description (probably, /proc/pid/fd).
// So don't reset its flags and r/w mode.
} else {
description->set_rw_mode(options);
description->set_file_flags(options);
}
u32 fd_flags = (options & O_CLOEXEC) ? FD_CLOEXEC : 0;
m_fds[fd].set(move(description), fd_flags);
return fd;