interpreter fixes
[nestedvm.git] / src / org / ibex / nestedvm / UnixRuntime.java
index a6847ee..151699f 100644 (file)
@@ -33,7 +33,9 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
                 
         // FEATURE: Do the proper mangling for non-unix hosts
         String userdir = getSystemProperty("user.dir");
                 
         // FEATURE: Do the proper mangling for non-unix hosts
         String userdir = getSystemProperty("user.dir");
-        cwd = userdir != null && userdir.startsWith("/") && File.separatorChar == '/'  ? userdir.substring(1) : "";
+        cwd = 
+            userdir != null && userdir.startsWith("/") && File.separatorChar == '/' && HostFS.hostRootDir().getParent() == null  
+            ? userdir.substring(1) : "";
     }
     
     // NOTE: getDisplayName() is a Java2 function
     }
     
     // NOTE: getDisplayName() is a Java2 function
@@ -304,6 +306,12 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
     private int exec(String normalizedPath, String[] argv, String[] envp) throws ErrnoException {
         if(argv.length == 0) argv = new String[]{""};
 
     private int exec(String normalizedPath, String[] argv, String[] envp) throws ErrnoException {
         if(argv.length == 0) argv = new String[]{""};
 
+        // NOTE: For this little hack to work nestedvm.root MUST be "."
+        /*try {
+            System.err.println("Execing normalized path: " + normalizedPath);
+            if(true) return exec(new Interpreter(normalizedPath),argv,envp);
+        } catch(IOException e) { throw new Error(e); }*/
+        
         Object o = gs.exec(this,normalizedPath);
         if(o == null) return -ENOENT;
 
         Object o = gs.exec(this,normalizedPath);
         if(o == null) return -ENOENT;
 
@@ -794,8 +802,14 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
         public File getRoot() { return root; }
         
         private static File hostRootDir() {
         public File getRoot() { return root; }
         
         private static File hostRootDir() {
+            if(getSystemProperty("nestedvm.root") != null) {
+                File f = new File(getSystemProperty("nestedvm.root"));
+                if(f.isDirectory()) return f;
+                // fall through to case below
+            }
             String cwd = getSystemProperty("user.dir");
             File f = new File(cwd != null ? cwd : ".");
             String cwd = getSystemProperty("user.dir");
             File f = new File(cwd != null ? cwd : ".");
+            if(!f.exists()) throw new Error("Couldn't get File for cwd");
             f = new File(f.getAbsolutePath());
             while(f.getParent() != null) f = new File(f.getParent());
             return f;
             f = new File(f.getAbsolutePath());
             while(f.getParent() != null) f = new File(f.getParent());
             return f;