X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fnestedvm%2FUnixRuntime.java;h=2b32965eeee982aab2fe03bd94aeb3a64e801d45;hb=ba5f49b65c5b2586de9b03a14a7842da143f3031;hp=1466a9b27f8b76fd24d49d41d486a5eb01d90d1a;hpb=3a9347de699c1d52ae6ffe35c21fa30cea1c8033;p=nestedvm.git diff --git a/src/org/ibex/nestedvm/UnixRuntime.java b/src/org/ibex/nestedvm/UnixRuntime.java index 1466a9b..2b32965 100644 --- a/src/org/ibex/nestedvm/UnixRuntime.java +++ b/src/org/ibex/nestedvm/UnixRuntime.java @@ -3,6 +3,8 @@ package org.ibex.nestedvm; import org.ibex.nestedvm.util.*; import java.io.*; import java.util.*; +import java.net.Socket; +import java.net.ServerSocket; // FEATURE: vfork @@ -86,14 +88,21 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { UnixRuntime[] tasks = gs.tasks; synchronized(gs) { if(pid != 0) { - if(tasks[pid] == null || tasks[pid].pid != pid) throw new Error("should never happen"); + UnixRuntime prev = tasks[pid]; + if(prev == null || prev == this || prev.pid != pid || prev.parent != parent) + throw new Error("should never happen"); + synchronized(parent.children) { + int i = parent.activeChildren.indexOf(prev); + if(i == -1) throw new Error("should never happen"); + parent.activeChildren.set(i,this); + } } else { int newpid = -1; int nextPID = gs.nextPID; - for(int i=nextPID;i= OPEN_MAX) return -EBADFD; + if(fds[fdn] == null) return -EBADFD; + if(!(fds[fdn] instanceof ListenSocketFD)) return -EBADFD; + try { + ServerSocket s = ((ListenSocketFD)fds[fdn]).s; + SocketFD fd = new SocketFD(s.accept()); + int n = addFD(fd); + if(n == -1) fd.close(); + return n; + } catch(IOException e) { + return -EIO; + } + } + // FEATURE: Run through the fork/wait stuff one more time public static class GlobalState { protected static final int OPEN = 1; @@ -536,7 +606,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { } } - private static class MP { + private static class MP implements Comparable { public MP(String path, FS fs) { this.path = path; this.fs = fs; } public String path; public FS fs; @@ -642,6 +712,9 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { } public synchronized Object exec(UnixRuntime r, String path) throws ErrnoException { + // FIXME: Hideous hack to make a standalone busybox possible + if(path.equals("bin/busybox") && Boolean.valueOf(getSystemProperty("nestedvm.busyboxhack")).booleanValue()) + return r.getClass(); FStat fstat = stat(r,path); if(fstat == null) return null; long mtime = fstat.mtime(); @@ -976,16 +1049,12 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { } private FD devZeroFD = new FD() { - public boolean readable() { return true; } - public boolean writable() { return true; } public int read(byte[] a, int off, int length) { Arrays.fill(a,off,off+length,(byte)0); return length; } public int write(byte[] a, int off, int length) { return length; } public int seek(int n, int whence) { return 0; } public FStat _fstat() { return new DevFStat(){ public int inode() { return ZERO_INODE; } }; } }; private FD devNullFD = new FD() { - public boolean readable() { return true; } - public boolean writable() { return true; } public int read(byte[] a, int off, int length) { return 0; } public int write(byte[] a, int off, int length) { return length; } public int seek(int n, int whence) { return 0; }