From 77fe8e8363140d600c4e9cfa4b5f6212a2c71234 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 6 Nov 2018 13:33:06 +0100 Subject: [PATCH] Add getppid(). --- Kernel/ProcFileSystem.cpp | 2 +- Kernel/Process.cpp | 11 ++++++++--- Kernel/Process.h | 9 +++++---- Kernel/Syscall.cpp | 2 ++ Kernel/Syscall.h | 1 + LibC/unistd.cpp | 5 +++++ 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Kernel/ProcFileSystem.cpp b/Kernel/ProcFileSystem.cpp index 23e05d3604a..2e597514e40 100644 --- a/Kernel/ProcFileSystem.cpp +++ b/Kernel/ProcFileSystem.cpp @@ -269,7 +269,7 @@ ByteBuffer procfs$summary() process->sid(), process->uid(), toString(process->state()), - process->parentPID(), + process->ppid(), process->timesScheduled(), process->number_of_open_file_descriptors(), process->tty() ? strrchr(process->tty()->ttyName().characters(), '/') + 1 : "n/a", diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index b55083ef471..e2078707813 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -558,7 +558,7 @@ Process* Process::createKernelProcess(void (*e)(), String&& name) return process; } -Process::Process(String&& name, uid_t uid, gid_t gid, pid_t parentPID, RingLevel ring, RetainPtr&& cwd, RetainPtr&& executable, TTY* tty, Process* fork_parent) +Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring, RetainPtr&& cwd, RetainPtr&& executable, TTY* tty, Process* fork_parent) : m_name(move(name)) , m_pid(next_pid++) // FIXME: RACE: This variable looks racy! , m_uid(uid) @@ -570,7 +570,7 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t parentPID, RingLevel , m_cwd(move(cwd)) , m_executable(move(executable)) , m_tty(tty) - , m_parentPID(parentPID) + , m_ppid(ppid) { if (fork_parent) { m_sid = fork_parent->m_sid; @@ -578,7 +578,7 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t parentPID, RingLevel } else { // FIXME: Use a ProcessHandle? Presumably we're executing *IN* the parent right now though.. InterruptDisabler disabler; - if (auto* parent = Process::fromPID(m_parentPID)) { + if (auto* parent = Process::fromPID(m_ppid)) { m_sid = parent->m_sid; m_pgid = parent->m_pgid; } @@ -1315,6 +1315,11 @@ pid_t Process::sys$getpid() return m_pid; } +pid_t Process::sys$getppid() +{ + return m_ppid; +} + pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options) { if (wstatus) diff --git a/Kernel/Process.h b/Kernel/Process.h index ad8b1817ee1..7558b8bfaf4 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -26,7 +26,7 @@ class Process : public InlineLinkedListNode { friend class InlineLinkedListNode; public: static Process* createKernelProcess(void (*entry)(), String&& name); - static Process* create_user_process(const String& path, uid_t, gid_t, pid_t parentPID, int& error, Vector&& arguments = Vector(), Vector&& environment = Vector(), TTY* = nullptr); + static Process* create_user_process(const String& path, uid_t, gid_t, pid_t ppid, int& error, Vector&& arguments = Vector(), Vector&& environment = Vector(), TTY* = nullptr); ~Process(); static Vector allProcesses(); @@ -67,7 +67,7 @@ public: gid_t gid() const { return m_gid; } uid_t euid() const { return m_euid; } gid_t egid() const { return m_egid; } - pid_t parentPID() const { return m_parentPID; } + pid_t ppid() const { return m_ppid; } const FarPtr& farPtr() const { return m_farPtr; } @@ -103,6 +103,7 @@ public: uid_t sys$geteuid(); gid_t sys$getegid(); pid_t sys$getpid(); + pid_t sys$getppid(); int sys$open(const char* path, int options); int sys$close(int fd); ssize_t sys$read(int fd, void* outbuf, size_t nread); @@ -179,7 +180,7 @@ private: friend class MemoryManager; friend bool scheduleNewProcess(); - Process(String&& name, uid_t, gid_t, pid_t parentPID, RingLevel, RetainPtr&& cwd = nullptr, RetainPtr&& executable = nullptr, TTY* = nullptr, Process* fork_parent = nullptr); + Process(String&& name, uid_t, gid_t, pid_t ppid, RingLevel, RetainPtr&& cwd = nullptr, RetainPtr&& executable = nullptr, TTY* = nullptr, Process* fork_parent = nullptr); void push_value_on_stack(dword); @@ -233,7 +234,7 @@ private: LinearAddress m_return_from_signal_trampoline; - pid_t m_parentPID { 0 }; + pid_t m_ppid { 0 }; static void notify_waiters(pid_t waitee, int exit_status, int signal); diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp index db0fc9aecfb..83ffab9631f 100644 --- a/Kernel/Syscall.cpp +++ b/Kernel/Syscall.cpp @@ -87,6 +87,8 @@ static DWORD handle(RegisterDump& regs, DWORD function, DWORD arg1, DWORD arg2, return current->sys$getgid(); case Syscall::SC_getpid: return current->sys$getpid(); + case Syscall::SC_getppid: + return current->sys$getppid(); case Syscall::SC_waitpid: return current->sys$waitpid((pid_t)arg1, (int*)arg2, (int)arg3); case Syscall::SC_mmap: diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h index e91aa1f4424..04cae541027 100644 --- a/Kernel/Syscall.h +++ b/Kernel/Syscall.h @@ -50,6 +50,7 @@ __ENUMERATE_SYSCALL(dup) \ __ENUMERATE_SYSCALL(dup2) \ __ENUMERATE_SYSCALL(sigaction) \ + __ENUMERATE_SYSCALL(getppid) \ #define DO_SYSCALL_A0(function) Syscall::invoke((dword)(function)) diff --git a/LibC/unistd.cpp b/LibC/unistd.cpp index 058222581f3..5ba180d38dc 100644 --- a/LibC/unistd.cpp +++ b/LibC/unistd.cpp @@ -44,6 +44,11 @@ pid_t getpid() return Syscall::invoke(Syscall::SC_getpid); } +pid_t getppid() +{ + return Syscall::invoke(Syscall::SC_getppid); +} + pid_t setsid() { int rc = Syscall::invoke(Syscall::SC_setsid);