示例#1
0
  public int run(
      SyscallReadableChannel in,
      SyscallWritableChannel out,
      NormalizedPath currentDirectory,
      InputStream stdin,
      OutputStream stdout,
      OutputStream stderr,
      Permissions permissions,
      Links links,
      Slave.Listener listener,
      String resourceDirectory)
      throws IOException, InterruptedException {
    mLogger.info("starting a slave application");

    mResourceDirectory = resourceDirectory;

    initializeInitProcess();

    Process process = new Process(mPidGenerator.next(), mInit);
    mInit.addChild(process);
    addProcess(process);

    Pipe slave2hub = Pipe.open();
    Pipe hub2slave = Pipe.open();
    Slave slave =
        new Slave(
            this,
            process,
            new SyscallReadableChannel(hub2slave.source()),
            new SyscallWritableChannel(slave2hub.sink()),
            currentDirectory,
            stdin,
            stdout,
            stderr,
            permissions,
            links,
            listener);
    process.add(slave);

    mSlaveHub =
        new SlaveHub(
            this,
            in,
            out,
            new SyscallReadableChannel(slave2hub.source()),
            new SyscallWritableChannel(hub2slave.sink()));

    new Thread(slave).start();
    mSlaveHub.work();
    synchronized (mAlarm) {
      while (!mProcesses.isEmpty()) {
        mAlarm.wait();
      }
    }

    return !mCancelled ? mExitStatus : 255;
  }
示例#2
0
  private void releaseProcess(Process process) {
    process.getParent().removeChild(process);
    for (Process child : process.getChildren()) {
      mInit.addChild(child);
      child.setParent(mInit);
    }

    Pid pid = process.getPid();
    mPidGenerator.release(pid);
    mLogger.info("released the process of pid %s", pid);
  }
示例#3
0
 /** This is for fork(2). */
 public Slave newProcess(
     PairId pairId,
     Process parent,
     NormalizedPath currentDirectory,
     Permissions permissions,
     Links links,
     Slave.Listener listener)
     throws IOException {
   Pid pid = mPidGenerator.next();
   Process process = new Process(pid, parent, parent.dupFileTable());
   parent.addChild(process);
   addProcess(process);
   return newSlave(pairId, process, currentDirectory, permissions, links, listener);
 }
示例#4
0
 private void initializeInitProcess() {
   Pid pid = new Pid(1);
   mPidGenerator.use(pid);
   mInit = new Process(pid);
 }