Explorar o código

Kernel: Implement Process::custody_for_dirfd

This allows deduplicating a bunch of code that has to work with
POSIX' *at syscall semantics.
sin-ack %!s(int64=2) %!d(string=hai) anos
pai
achega
5c1d5ed51d
Modificáronse 2 ficheiros con 13 adicións e 0 borrados
  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; });
     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:
 private:
+    ErrorOr<NonnullRefPtr<Custody>> custody_for_dirfd(int dirfd);
+
     SpinlockProtected<Thread::ListInProcess>& thread_list() { return m_thread_list; }
     SpinlockProtected<Thread::ListInProcess>& thread_list() { return m_thread_list; }
     SpinlockProtected<Thread::ListInProcess> const& thread_list() const { return m_thread_list; }
     SpinlockProtected<Thread::ListInProcess> const& thread_list() const { return m_thread_list; }