module ChildProcess
Constants
- VERSION
Attributes
logger[W]
Public Class Methods
arch()
click to toggle source
# File lib/childprocess.rb, line 105 def arch @arch ||= ( host_cpu = RbConfig::CONFIG['host_cpu'].downcase case host_cpu when /i[3456]86/ if workaround_older_macosx_misreported_cpu? # Workaround case: older 64-bit Darwin Rubies misreported as i686 "x86_64" else "i386" end when /amd64|x86_64/ "x86_64" when /ppc|powerpc/ "powerpc" else host_cpu end ) end
close_on_exec(file)
click to toggle source
By default, a child process will inherit open file descriptors from the parent process. This helper provides a cross-platform way of making sure that doesn’t happen for the given file/io.
# File lib/childprocess.rb, line 132 def close_on_exec(file) if file.respond_to?(:close_on_exec=) file.close_on_exec = true else raise Error, "not sure how to set close-on-exec for #{file.inspect} on #{platform_name.inspect}" end end
jruby?()
click to toggle source
# File lib/childprocess.rb, line 53 def jruby? RUBY_ENGINE == 'jruby' end
linux?()
click to toggle source
# File lib/childprocess.rb, line 49 def linux? os == :linux end
logger()
click to toggle source
# File lib/childprocess.rb, line 28 def logger return @logger if defined?(@logger) and @logger @logger = Logger.new($stderr) @logger.level = $DEBUG ? Logger::DEBUG : Logger::INFO @logger end
new(*args)
click to toggle source
# File lib/childprocess.rb, line 16 def new(*args) case os when :macosx, :linux, :solaris, :bsd, :cygwin, :aix Unix::Process.new(*args) when :windows Windows::Process.new(*args) else raise Error, "unsupported platform #{platform_name.inspect}" end end
Also aliased as: build
os()
click to toggle source
# File lib/childprocess.rb, line 77 def os return :windows if ENV['FAKE_WINDOWS'] == 'true' @os ||= ( require "rbconfig" host_os = RbConfig::CONFIG['host_os'].downcase case host_os when /linux/ :linux when /darwin|mac os/ :macosx when /mswin|msys|mingw32/ :windows when /cygwin/ :cygwin when /solaris|sunos/ :solaris when /bsd|dragonfly/ :bsd when /aix/ :aix else raise Error, "unknown os: #{host_os.inspect}" end ) end
platform()
click to toggle source
# File lib/childprocess.rb, line 37 def platform os end
platform_name()
click to toggle source
# File lib/childprocess.rb, line 41 def platform_name @platform_name ||= "#{arch}-#{os}" end
posix_spawn=(bool)
click to toggle source
Set this to true to enable experimental use of posix_spawn.
# File lib/childprocess.rb, line 73 def posix_spawn=(bool) @posix_spawn = bool end
posix_spawn?()
click to toggle source
# File lib/childprocess.rb, line 65 def posix_spawn? false end
posix_spawn_chosen_explicitly?()
click to toggle source
# File lib/childprocess.rb, line 61 def posix_spawn_chosen_explicitly? @posix_spawn || %w[1 true].include?(ENV['CHILDPROCESS_POSIX_SPAWN']) end
unix?()
click to toggle source
# File lib/childprocess.rb, line 45 def unix? !windows? end
windows?()
click to toggle source
# File lib/childprocess.rb, line 57 def windows? os == :windows end
Private Class Methods
is_64_bit?()
click to toggle source
@return [Boolean] ‘true` if this Ruby represents `1` in 64 bits (8 bytes).
# File lib/childprocess.rb, line 162 def is_64_bit? 1.size == 8 end
warn_once(msg)
click to toggle source
# File lib/childprocess.rb, line 142 def warn_once(msg) @warnings ||= {} unless @warnings[msg] @warnings[msg] = true logger.warn msg end end
workaround_older_macosx_misreported_cpu?()
click to toggle source
Workaround: detect the situation that an older Darwin Ruby is actually 64-bit, but is misreporting cpu as i686, which would imply 32-bit.
@return [Boolean] ‘true` if:
(a) on Mac OS X (b) actually running in 64-bit mode
# File lib/childprocess.rb, line 157 def workaround_older_macosx_misreported_cpu? os == :macosx && is_64_bit? end