Sha256: 7f35e5beacebf92e8fcbb0ef21ddd60c893c4627e2844aabaed2cdd1d78f90ad

Contents?: true

Size: 1.25 KB

Versions: 16

Compression:

Stored size: 1.25 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 {
          exec_r.close
          set_env

          STDOUT.reopen(stdout || "/dev/null")
          STDERR.reopen(stderr || "/dev/null")

          if duplex?
            STDIN.reopen(reader)
            writer.close
          end

          begin
            exec(*@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

16 entries across 16 versions & 5 rubygems

Version Path
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/childprocess-0.3.2/lib/childprocess/unix/fork_exec_process.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/childprocess-0.3.2/lib/childprocess/unix/fork_exec_process.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/childprocess-0.3.2/lib/childprocess/unix/fork_exec_process.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/childprocess-0.3.2/lib/childprocess/unix/fork_exec_process.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/childprocess-0.3.2/lib/childprocess/unix/fork_exec_process.rb
resque-pool-0.3.0 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/unix/fork_exec_process.rb
ftl-0.2.0 vendor/bundle/gems/childprocess-0.3.2/lib/childprocess/unix/fork_exec_process.rb
childprocess-0.3.2 lib/childprocess/unix/fork_exec_process.rb
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/unix/fork_exec_process.rb
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/unix/fork_exec_process.rb
frameworks-capybara-0.2.0.rc4 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/unix/fork_exec_process.rb
frameworks-capybara-0.2.0.rc3 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/unix/fork_exec_process.rb
frameworks-capybara-0.2.0.rc2 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/unix/fork_exec_process.rb
resque-pool-0.3.0.beta.2 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/unix/fork_exec_process.rb
childprocess-0.3.1 lib/childprocess/unix/fork_exec_process.rb
childprocess-0.3.0 lib/childprocess/unix/fork_exec_process.rb