Class: R10K::Util::Subprocess::Runner::POSIX Private

Inherits:
R10K::Util::Subprocess::Runner show all
Defined in:
lib/r10k/util/subprocess/runner/posix.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Implement a POSIX command runner by using fork/exec.

This implementation is optimized to run commands in the background, and has a few noteworthy implementation details.

First off, when the child process is forked, it calls setsid() to detach from the controlling TTY. This has two main ramifications: sending signals will never be send to the forked process, and the forked process does not have access to stdin.

Instance Attribute Summary

Attributes inherited from R10K::Util::Subprocess::Runner

#cwd, #result

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ POSIX

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of POSIX.



18
19
20
21
# File 'lib/r10k/util/subprocess/runner/posix.rb', line 18

def initialize(argv)
  @argv = argv
  mkpipes
end

Instance Method Details

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/r10k/util/subprocess/runner/posix.rb', line 23

def run
  # Create a pipe so that the parent can verify that the child process
  # successfully executed. The pipe will be closed on a successful exec(),
  # and will contain an error message on failure.
  exec_r, exec_w = pipe

  @stdout_pump = R10K::Util::Subprocess::Runner::Pump.new(@stdout_r)
  @stderr_pump = R10K::Util::Subprocess::Runner::Pump.new(@stderr_r)
  pid = fork do
    exec_r.close
    execute_child(exec_w)
  end

  exec_w.close
  @stdout_pump.start
  @stderr_pump.start

  execute_parent(exec_r, pid)

  @result
end