Przeglądaj źródła

Add an open method to /proc and some subdirectories

This addresses issue #461.
Don Porter 5 lat temu
rodzic
commit
e62a021fd8

+ 16 - 3
LibOS/shim/src/fs/proc/fs.c

@@ -83,7 +83,23 @@ static int proc_root_stat (const char * name, struct stat * buf)
     return 0;
 }
 
+
+static int proc_root_open (struct shim_handle * hdl,
+                           const char * name, int flags)
+{
+
+    if (flags & (O_WRONLY|O_RDWR))
+        return -EISDIR;
+
+    // Don't really need to do any work here, but keeping as a placeholder,
+    // just in case.
+
+    return 0;
+
+}
+
 struct proc_fs_ops fs_proc_root = {
+        .open     = &proc_root_open,
         .mode     = &proc_root_mode,
         .stat     = &proc_root_stat,
     };
@@ -215,9 +231,6 @@ static int proc_open (struct shim_handle * hdl, struct shim_dentry * dent,
     if ((ret = proc_match_name(rel_path, &ent)) < 0)
         return ret;
 
-    if (ent->dir)
-        return -EISDIR;
-
     if (!ent->fs_ops || !ent->fs_ops->open)
         return -EACCES;
 

+ 15 - 0
LibOS/shim/src/fs/proc/thread.c

@@ -636,6 +636,20 @@ static const struct proc_fs_ops fs_thread_maps = {
             .stat           = &proc_thread_maps_stat,
         };
 
+static int proc_thread_dir_open (struct shim_handle * hdl,
+                                 const char * name, int flags)
+{
+
+    if (flags & (O_WRONLY|O_RDWR))
+        return -EISDIR;
+
+    // Don't really need to do any work here, but keeping as a placeholder,
+    // just in case.
+
+    return 0;
+
+}
+
 static int proc_thread_dir_mode (const char * name, mode_t * mode)
 {
     const char * next;
@@ -738,6 +752,7 @@ const struct proc_nm_ops nm_thread = {
         };
 
 const struct proc_fs_ops fs_thread = {
+            .open   = &proc_thread_dir_open,
             .mode   = &proc_thread_dir_mode,
             .stat   = &proc_thread_dir_stat,
         };

+ 24 - 0
LibOS/shim/test/regression/40_proc.py

@@ -0,0 +1,24 @@
+import os, sys, mmap
+from regression import Regression
+
+loader = sys.argv[1]
+
+# Running Bootstrap
+regression = Regression(loader, "proc")
+
+regression.add_check(name="Base /proc files present",
+    check=lambda res: "/proc/1/.." in res[0].out and \
+                      "/proc/1/cwd" in res[0].out and \
+                      "/proc/1/exe" in res[0].out and \
+                      "/proc/1/root" in res[0].out and \
+                      "/proc/1/fd" in res[0].out and \
+                      "/proc/1/maps" in res[0].out and \
+                      "/proc/." in res[0].out and \
+                      "/proc/1" in res[0].out and \
+                      "/proc/self" in res[0].out and \
+                      "/proc/meminfo" in res[0].out and \
+                      "/proc/cpuinfo" in res[0].out)
+
+
+rv = regression.run_checks()
+if rv: sys.exit(rv)

+ 2 - 0
LibOS/shim/test/regression/Makefile

@@ -58,6 +58,8 @@ regression: $(target)
 	@for f in $(wildcard 00_*.py); do env $(PYTHONENV) python3 $$f $(RUNTIME)/pal-$(PAL_HOST) || exit $$?; done
 	@echo "\n\nSyscall Support:"
 	@for f in $(wildcard 30_*.py); do env $(PYTHONENV) python3 $$f $(RUNTIME)/pal-$(PAL_HOST) || exit $$?; done
+	@echo "\n\nFile System Support:"
+	@for f in $(wildcard 40_*.py); do env $(PYTHONENV) python3 $$f $(RUNTIME)/pal-$(PAL_HOST) || exit $$?; done
 	@echo "\n\nSocket Support:"
 	@for f in $(wildcard 80_*.py); do env $(PYTHONENV) python3 $$f $(RUNTIME)/pal-$(PAL_HOST) || exit $$?; done
 	@echo "\n\nLarge File Support:"

+ 6 - 3
LibOS/shim/test/native/proc.c → LibOS/shim/test/regression/proc.c

@@ -1,6 +1,3 @@
-/* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
-/* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
-
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
@@ -22,7 +19,12 @@ int main(int argc, char ** argv)
         printf("/proc/1/%s\n", dirent->d_name);
     closedir(dir);
 
+    // Children end up inheriting junk if we don't flush here.
+    fflush(stdout);
 
+    /* This code tickles a bug in exit/wait for PIDs/IPC; created an issue (#532), will
+     * revisit after landing some related IPC fixes that are pending.*/
+#if 0
     for (int i = 0 ; i < 3 ; i++) {
         pid_t pid = fork();
 
@@ -36,6 +38,7 @@ int main(int argc, char ** argv)
             exit(0);
         }
     }
+#endif
 
     dir = opendir("/proc");
     if (!dir) {