浏览代码

Add /proc/PID/cwd, a symlink to the process's current directory.

Andreas Kling 6 年之前
父节点
当前提交
36b3dc6c32
共有 2 个文件被更改,包括 9 次插入1 次删除
  1. 8 0
      Kernel/ProcFileSystem.cpp
  2. 1 1
      Userland/sh.cpp

+ 8 - 0
Kernel/ProcFileSystem.cpp

@@ -138,6 +138,13 @@ ByteBuffer procfs$pid_exe(Process& process)
     return VirtualFileSystem::the().absolutePath(inode).toByteBuffer();
     return VirtualFileSystem::the().absolutePath(inode).toByteBuffer();
 }
 }
 
 
+ByteBuffer procfs$pid_cwd(Process& process)
+{
+    ProcessInspectionHandle handle(process);
+    auto inode = process.cwdInode();
+    return VirtualFileSystem::the().absolutePath(inode).toByteBuffer();
+}
+
 void ProcFileSystem::addProcess(Process& process)
 void ProcFileSystem::addProcess(Process& process)
 {
 {
     InterruptDisabler disabler;
     InterruptDisabler disabler;
@@ -151,6 +158,7 @@ void ProcFileSystem::addProcess(Process& process)
     addFile(createGeneratedFile("fds", [&process] { return procfs$pid_fds(process); }), dir.index());
     addFile(createGeneratedFile("fds", [&process] { return procfs$pid_fds(process); }), dir.index());
     if (process.executableInode().isValid())
     if (process.executableInode().isValid())
         addFile(createGeneratedFile("exe", [&process] { return procfs$pid_exe(process); }, 00120777), dir.index());
         addFile(createGeneratedFile("exe", [&process] { return procfs$pid_exe(process); }, 00120777), dir.index());
+    addFile(createGeneratedFile("cwd", [&process] { return procfs$pid_cwd(process); }, 00120777), dir.index());
 }
 }
 
 
 void ProcFileSystem::removeProcess(Process& process)
 void ProcFileSystem::removeProcess(Process& process)

+ 1 - 1
Userland/sh.cpp

@@ -186,7 +186,7 @@ static int sh_cd(int argc, const char** argv)
     const char* path = canonicalPath.string().characters();
     const char* path = canonicalPath.string().characters();
 
 
     struct stat st;
     struct stat st;
-    int rc = lstat(path, &st);
+    int rc = stat(path, &st);
     if (rc < 0) {
     if (rc < 0) {
         printf("lstat(%s) failed: %s\n", path, strerror(errno));
         printf("lstat(%s) failed: %s\n", path, strerror(errno));
         return 1;
         return 1;