summaryrefslogtreecommitdiff
path: root/Kernel/Process.cpp
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2020-01-15 14:03:14 +0300
committerAndreas Kling <awesomekling@gmail.com>2020-01-17 21:49:58 +0100
commit8642a7046cf74e6ac79934cab0edacd83645d445 (patch)
tree86926856f111f634f6144c6351922be699b264d8 /Kernel/Process.cpp
parentae64fd1b27dfd10a5854aafa58550b00c58a285c (diff)
downloadserenity-8642a7046cf74e6ac79934cab0edacd83645d445.zip
Kernel: Let inodes provide pre-open file descriptions
Some magical inodes, such as /proc/pid/fd/fileno, are going to want to open() to a custom FileDescription, so add a hook for that.
Diffstat (limited to 'Kernel/Process.cpp')
-rw-r--r--Kernel/Process.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index e10d5405e2..ff8522e75a 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -1908,8 +1908,14 @@ int Process::sys$open(const Syscall::SC_open_params* user_params)
if (result.is_error())
return result.error();
auto description = result.value();
- description->set_rw_mode(options);
- description->set_file_flags(options);
+ 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;