示例#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;
  }