Chia-Che Tsai 9 years ago
parent
commit
a3238c82c4

+ 23 - 4
LibOS/shim/src/bookkeep/shim_handle.c

@@ -452,10 +452,29 @@ void close_handle (struct shim_handle * hdl)
 #endif
 
     if (!opened) {
-        if (hdl->type != TYPE_DIR &&
-            hdl->fs && hdl->fs->fs_ops &&
-            hdl->fs->fs_ops->close)
-            hdl->fs->fs_ops->close(hdl);
+        if (hdl->type == TYPE_DIR) {
+            struct shim_dir_handle * dir = &hdl->info.dir;
+
+            if (dir->dot) {
+                put_dentry(dir->dot);
+                dir->dot = NULL;
+            }
+
+            if (dir->dotdot) {
+                put_dentry(dir->dotdot);
+                dir->dotdot = NULL;
+            }
+
+            while (*dir->ptr) {
+                struct shim_dentry * dent = *dir->ptr;
+                put_dentry(dent);
+                *(dir->ptr++) = NULL;
+            }
+        } else {
+            if (hdl->fs && hdl->fs->fs_ops &&
+                hdl->fs->fs_ops->close)
+                hdl->fs->fs_ops->close(hdl);
+        }
     }
 
     put_handle(hdl);

+ 2 - 0
LibOS/shim/src/fs/shim_namei.c

@@ -1052,7 +1052,9 @@ done_read:
     memcpy(hdl->fs_type, fs->type, sizeof(fs->type));
     hdl->dentry = dent;
     hdl->flags = flags;
+    get_dentry(dent);
     hdl->info.dir.dot = dent;
+    put_dentry(dent->parent);
     hdl->info.dir.dotdot = dent->parent;
     hdl->info.dir.buf = children;
     hdl->info.dir.ptr = children;

+ 2 - 4
LibOS/shim/src/sys/shim_open.c

@@ -371,8 +371,7 @@ size_t shim_do_getdents (int fd, struct linux_dirent * buf, size_t count)
         dent = *dirhdl->ptr;
         ASSIGN_DIRENT(dent, dentry_get_name(dent), 0);
         put_dentry(dent);
-        *dirhdl->ptr = NULL;
-        dirhdl->ptr++;
+        *(dirhdl->ptr++) = NULL;
     }
 
 #undef DIRENT_SIZE
@@ -441,8 +440,7 @@ size_t shim_do_getdents64 (int fd, struct linux_dirent64 * buf, size_t count)
         dent = *dirhdl->ptr;
         ASSIGN_DIRENT(dent, dentry_get_name(dent), 0);
         put_dentry(dent);
-        *dirhdl->ptr = NULL;
-        dirhdl->ptr++;
+        *(dirhdl->ptr++) = NULL;
     }
 
 #undef DIRENT_SIZE

+ 27 - 3
LibOS/shim/test/apps/python/Makefile

@@ -1,16 +1,40 @@
-manifests = python.manifest
+manifests = python.manifest python-local.manifest
 
 all debug: $(manifests)
 
+PYTHON_SRC = Python-2.7.9
+PYTHON_INSTALL = $(PYTHON_SRC)/build
+local: python-local
+
+python-local: $(PYTHON_INSTALL)/bin/python
+	cp -f $< $@
+
+$(PYTHON_INSTALL)/bin/python: $(PYTHON_SRC)/Makefile
+	cd $(PYTHON_SRC) && make
+	cd $(PYTHON_SRC) && make install
+
+$(PYTHON_SRC)/Makefile: $(PYTHON_SRC)/configure
+	cd $(PYTHON_SRC) && \
+		./configure --prefix=$(shell readlink -f $(PYTHON_INSTALL))
+
+$(PYTHON_SRC)/configure: $(PYTHON_SRC).tgz
+	tar -xzf $<
+
 test_targets =  testsamplebash
 
 test: all $(test_targets)
 
-%.manifest: %.manifest.template
+python.manifest: python.manifest.template
 	make -C .. python/$@ appdir=python/
 
+python-local.manifest: python-local.manifest.template
+	make -C .. python/$@ appdir=python/ \
+		extra_rules="-e 's:\\\$$\$$(PYTHONDIR):$(shell readlink -f $(PYTHON_INSTALL)):g'"
+
+distclean: clean
+	rm -rf $(PYTHON_SRC) python-local
+
 clean: clean-manifests
-distclean: clean-manifests
 
 clean-manifests:
 	rm -rf $(manifests)

BIN
LibOS/shim/test/apps/python/Python-2.7.9.tgz


+ 38 - 0
LibOS/shim/test/apps/python/python-local.manifest.template

@@ -0,0 +1,38 @@
+#!$(PAL)
+
+loader.preload = file:$(SHIMPATH)
+loader.exec = file:python-local
+loader.execname = python
+loader.env.LD_LIBRARY_PATH = $(PYTHONDIR)/lib:/lib:/lib/x86_64-linux-gnu:/usr/lib:/usr/lib/x86_64-linux-gnu
+loader.env.PATH = $(PYTHONDIR)/bin:/usr/bin:/bin
+loader.env.USERNAME =
+loader.env.HOME =
+loader.env.PWD =
+loader.env.PYTHONPATH = $(PYTHONDIR)/bin/python
+loader.env.PYTHONHOME = $(PYTHONDIR)
+loader.debug_type = none
+
+fs.mount.root.type = chroot
+fs.mount.root.uri = file:
+
+fs.mount.other.python.type = chroot
+fs.mount.other.python.path = $(PYTHONDIR)
+fs.mount.other.python.uri = file:$(PYTHONDIR)
+
+fs.mount.other.lib1.type = chroot
+fs.mount.other.lib1.path = /lib
+fs.mount.other.lib1.uri = file:$(GLIBCDIR)
+
+fs.mount.other.lib2.type = chroot
+fs.mount.other.lib2.path = /lib/x86_64-linux-gnu
+fs.mount.other.lib2.uri = file:/lib/x86_64-linux-gnu
+
+fs.mount.other.bin.type = chroot
+fs.mount.other.bin.path = /bin
+fs.mount.other.bin.uri = file:/bin
+
+fs.mount.other.usr.type = chroot
+fs.mount.other.usr.path = /usr
+fs.mount.other.usr.uri = file:/usr
+
+sys.brk.size = 262144  # 256K