Sha256: 0dc328b7dfde05fe8cfb5bdcd4003faf21ea22a23b90e04e73e7568f4407f43b

Contents?: true

Size: 1.75 KB

Versions: 42

Compression:

Stored size: 1.75 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 = Kernel.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 if leader?

          if @cwd
            Dir.chdir(@cwd)
          end

          exec_r.close
          set_env

          if stdout
            STDOUT.reopen(stdout)
          else
            STDOUT.reopen("/dev/null", "a+")
          end
          if stderr
            STDERR.reopen(stderr)
          else
            STDERR.reopen("/dev/null", "a+")
          end

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

          executable, *args = @args

          begin
            Kernel.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

42 entries across 30 versions & 7 rubygems

Version Path
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/childprocess-4.0.0/lib/childprocess/unix/fork_exec_process.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/childprocess-3.0.0/lib/childprocess/unix/fork_exec_process.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/childprocess-3.0.0/lib/childprocess/unix/fork_exec_process.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/childprocess-3.0.0/lib/childprocess/unix/fork_exec_process.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/childprocess-4.0.0/lib/childprocess/unix/fork_exec_process.rb
tdiary-5.1.4 vendor/bundle/ruby/2.7.0/gems/childprocess-3.0.0/lib/childprocess/unix/fork_exec_process.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/childprocess-4.0.0/lib/childprocess/unix/fork_exec_process.rb
tdiary-5.1.3 vendor/bundle/ruby/2.7.0/gems/childprocess-3.0.0/lib/childprocess/unix/fork_exec_process.rb
tdiary-5.1.3 vendor/bundle/ruby/2.6.0/gems/childprocess-3.0.0/lib/childprocess/unix/fork_exec_process.rb
childprocess-4.0.0 lib/childprocess/unix/fork_exec_process.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/childprocess-3.0.0/lib/childprocess/unix/fork_exec_process.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/childprocess-3.0.0/lib/childprocess/unix/fork_exec_process.rb
tdiary-5.1.2 vendor/bundle/ruby/2.7.0/gems/childprocess-3.0.0/lib/childprocess/unix/fork_exec_process.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/childprocess-3.0.0/lib/childprocess/unix/fork_exec_process.rb
tdiary-5.1.1 vendor/bundle/ruby/2.7.0/gems/childprocess-3.0.0/lib/childprocess/unix/fork_exec_process.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/childprocess-3.0.0/lib/childprocess/unix/fork_exec_process.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/childprocess-3.0.0/lib/childprocess/unix/fork_exec_process.rb
tdiary-5.1.0 vendor/bundle/gems/childprocess-3.0.0/lib/childprocess/unix/fork_exec_process.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/childprocess-3.0.0/lib/childprocess/unix/fork_exec_process.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/childprocess-3.0.0/lib/childprocess/unix/fork_exec_process.rb