Ejemplo n.º 1
0
  /** This is for thr_new(2) (fork(2) also uses this internally). */
  public Slave newSlave(
      PairId newPairId,
      Process process,
      NormalizedPath currentDirectory,
      Permissions permissions,
      Links links,
      Slave.Listener listener)
      throws IOException {
    Pipe slave2hub = Pipe.open();
    Pipe hub2slave = Pipe.open();

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

    mSlaveHub.addSlave(
        new SyscallReadableChannel(slave2hub.source()),
        new SyscallWritableChannel(hub2slave.sink()),
        newPairId);

    return slave;
  }
Ejemplo n.º 2
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;
  }