summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorsin-ack <sin-ack@users.noreply.github.com>2022-10-01 11:28:27 +0000
committerAndrew Kaster <andrewdkaster@gmail.com>2022-12-11 19:55:37 -0700
commit5c1d5ed51da2cf3b9463413f704ea0e740950736 (patch)
treef3c2fac7be427769a099a68da7342a64499bd780 /Kernel
parent5b335e7fbab7e4b3b2428dd2a0a82a7edb4d75bc (diff)
downloadserenity-5c1d5ed51da2cf3b9463413f704ea0e740950736.zip
Kernel: Implement Process::custody_for_dirfd
This allows deduplicating a bunch of code that has to work with POSIX' *at syscall semantics.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Process.cpp11
-rw-r--r--Kernel/Process.h2
2 files changed, 13 insertions, 0 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index 4e21066044..1165d7ff25 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -1100,4 +1100,15 @@ RefPtr<Custody const> Process::executable() const
return m_executable.with([](auto& executable) { return executable; });
}
+ErrorOr<NonnullRefPtr<Custody>> Process::custody_for_dirfd(int dirfd)
+{
+ if (dirfd == AT_FDCWD)
+ return current_directory();
+
+ auto base_description = TRY(open_file_description(dirfd));
+ if (!base_description->custody())
+ return EINVAL;
+ return *base_description->custody();
+}
+
}
diff --git a/Kernel/Process.h b/Kernel/Process.h
index bf0c1616c2..3147965db3 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -844,6 +844,8 @@ public:
}
private:
+ ErrorOr<NonnullRefPtr<Custody>> custody_for_dirfd(int dirfd);
+
SpinlockProtected<Thread::ListInProcess>& thread_list() { return m_thread_list; }
SpinlockProtected<Thread::ListInProcess> const& thread_list() const { return m_thread_list; }