From e895d6c48e9ee0c7ed78942a1f17fd4840a055a9 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 3 Feb 2019 04:54:52 +0100 Subject: [PATCH] Kernel: Add /proc/self, a symlink to the /proc/$PID. This will be useful for implementing things like /dev/stdin. --- Kernel/ProcFileSystem.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Kernel/ProcFileSystem.cpp b/Kernel/ProcFileSystem.cpp index 3030efa29e..5db983fc29 100644 --- a/Kernel/ProcFileSystem.cpp +++ b/Kernel/ProcFileSystem.cpp @@ -150,6 +150,13 @@ ByteBuffer procfs$pid_cwd(Process& process) return VFS::the().absolute_path(*inode).to_byte_buffer(); } +ByteBuffer procfs$self(SynthFSInode&) +{ + char buffer[16]; + ksprintf(buffer, "%u", current->pid()); + return ByteBuffer::copy((const byte*)buffer, strlen(buffer)); +} + void ProcFS::add_process(Process& process) { InterruptDisabler disabler; @@ -400,6 +407,7 @@ bool ProcFS::initialize() add_file(create_generated_file("cpuinfo", procfs$cpuinfo)); add_file(create_generated_file("inodes", procfs$inodes)); add_file(create_generated_file("dmesg", procfs$dmesg)); + add_file(create_generated_file("self", procfs$self, 00120777)); m_sys_dir = add_file(create_directory("sys")); return true; }