Sha256: d760bf0e80ebbe2eff59929d7b9cb9859b3e0a55286eafc45a6580096517206b
Contents?: true
Size: 1.59 KB
Versions: 1
Compression:
Stored size: 1.59 KB
Contents
module ChildProcess module Unix class ForkExecProcess < Process private def launch_process if @io stdout = @io.stdout stderr = @io.stderr end # pipe used to detect exec() failure exec_r, exec_w = ::IO.pipe ChildProcess.close_on_exec exec_w if duplex? reader, writer = ::IO.pipe end @pid = fork { # Children of the forked process will inherit its process group # This is to make sure that all grandchildren dies when this Process instance is killed ::Process.setpgid 0, 0 unless keep_pgid? if @cwd Dir.chdir(@cwd) end exec_r.close set_env STDOUT.reopen(stdout || "/dev/null") STDERR.reopen(stderr || "/dev/null") if duplex? STDIN.reopen(reader) writer.close end executable, *args = @args begin exec([executable, executable], *args) rescue SystemCallError => ex exec_w << ex.message end } exec_w.close if duplex? io._stdin = writer reader.close end # if we don't eventually get EOF, exec() failed unless exec_r.eof? raise LaunchError, exec_r.read || "executing command with #{@args.inspect} failed" end ::Process.detach(@pid) if detach? end def set_env @environment.each { |k, v| ENV[k.to_s] = v.nil? ? nil : v.to_s } end end # Process end # Unix end # ChildProcess
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
childprocess-0.4.2 | lib/childprocess/unix/fork_exec_process.rb |