Bläddra i källkod

Kernel: Implement Process::custody_for_dirfd

This allows deduplicating a bunch of code that has to work with
POSIX' *at syscall semantics.
sin-ack 2 år sedan
förälder
incheckning
5c1d5ed51d
2 ändrade filer med 13 tillägg och 0 borttagningar
  1. 11 0
      Kernel/Process.cpp
  2. 2 0
      Kernel/Process.h

+ 11 - 0
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();
+}
+
 }

+ 2 - 0
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; }