From 9a41dda02922cc210915a044af57ea90bf68a662 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Sat, 28 Sep 2019 23:00:38 +0300 Subject: [PATCH] Kernel: Expose blocking and cloexec fd flags in ProcFS --- Kernel/FileSystem/ProcFS.cpp | 4 ++++ Kernel/Process.cpp | 9 +++++++++ Kernel/Process.h | 1 + 3 files changed, 14 insertions(+) diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index 23c05c1dd83..ba5819412d6 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -211,12 +211,16 @@ Optional procfs$pid_fds(InodeIdentifier identifier) auto* description = process.file_description(i); if (!description) continue; + bool cloexec = process.fd_flags(i) & FD_CLOEXEC; + JsonObjectSerializer description_object = array.add_object(); description_object.add("fd", i); description_object.add("absolute_path", description->absolute_path()); description_object.add("seekable", description->file().is_seekable()); description_object.add("class", description->file().class_name()); description_object.add("offset", description->offset()); + description_object.add("cloexec", cloexec); + description_object.add("blocking", description->is_blocking()); } array.finish(); return builder.build(); diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 5921ebd6792..f4cbdbc3af4 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -917,6 +917,15 @@ const FileDescription* Process::file_description(int fd) const return nullptr; } +int Process::fd_flags(int fd) const +{ + if (fd < 0) + return -1; + if (fd < m_fds.size()) + return m_fds[fd].flags; + return -1; +} + ssize_t Process::sys$get_dir_entries(int fd, void* buffer, ssize_t size) { if (size < 0) diff --git a/Kernel/Process.h b/Kernel/Process.h index b4760ff6674..52c20ae9e37 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -95,6 +95,7 @@ public: FileDescription* file_description(int fd); const FileDescription* file_description(int fd) const; + int fd_flags(int fd) const; template static void for_each(Callback);