Module: Aggkit::ChildProcess
- Defined in:
- lib/aggkit/childprocess.rb,
lib/aggkit/childprocess/unix.rb,
lib/aggkit/childprocess/errors.rb,
lib/aggkit/childprocess/unix/io.rb,
lib/aggkit/childprocess/version.rb,
lib/aggkit/childprocess/jruby/io.rb,
lib/aggkit/childprocess/unix/lib.rb,
lib/aggkit/childprocess/jruby/pump.rb,
lib/aggkit/childprocess/windows/io.rb,
lib/aggkit/childprocess/abstract_io.rb,
lib/aggkit/childprocess/windows/lib.rb,
lib/aggkit/childprocess/unix/process.rb,
lib/aggkit/childprocess/jruby/process.rb,
lib/aggkit/childprocess/windows/handle.rb,
lib/aggkit/childprocess/tools/generator.rb,
lib/aggkit/childprocess/windows/process.rb,
lib/aggkit/childprocess/windows/structs.rb,
lib/aggkit/childprocess/abstract_process.rb,
lib/aggkit/childprocess/unix/fork_exec_process.rb,
lib/aggkit/childprocess/windows/process_builder.rb,
lib/aggkit/childprocess/unix/posix_spawn_process.rb,
lib/aggkit/childprocess/jruby.rb
Defined Under Namespace
Modules: JRuby, Tools, Unix, Windows
Classes: AbstractIO, AbstractProcess, Error, InvalidEnvironmentVariable, LaunchError, MissingPlatformError, SubclassResponsibility, TimeoutError
Constant Summary
collapse
- VERSION =
'0.9.0'
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.logger ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/aggkit/childprocess.rb', line 38
def logger
return @logger if defined?(@logger) && @logger
@logger = Logger.new($stderr)
@logger.level = $DEBUG ? Logger::DEBUG : Logger::INFO
@logger
end
|
.posix_spawn=(value) ⇒ Object
Set this to true to enable experimental use of posix_spawn.
101
102
103
|
# File 'lib/aggkit/childprocess.rb', line 101
def posix_spawn=(value)
@posix_spawn = value
end
|
Class Method Details
.arch ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/aggkit/childprocess.rb', line 129
def arch
@arch ||= begin
host_cpu = RbConfig::CONFIG['host_cpu'].downcase
case host_cpu
when /i[3456]86/
if workaround_older_macosx_misreported_cpu?
'x86_64'
else
'i386'
end
when /amd64|x86_64/
'x86_64'
when /ppc|powerpc/
'powerpc'
else
host_cpu
end
end
end
|
.close_on_exec(file) ⇒ Object
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.
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/aggkit/childprocess.rb', line 156
def close_on_exec(file)
if file.respond_to?(:close_on_exec=)
file.close_on_exec = true
elsif file.respond_to?(:fcntl) && defined?(Fcntl::FD_CLOEXEC)
file.fcntl Fcntl::F_SETFD, Fcntl::FD_CLOEXEC
if jruby? && posix_spawn?
fileno = JRuby.posix_fileno_for(file)
Unix::Lib.fcntl fileno, Fcntl::F_SETFD, Fcntl::FD_CLOEXEC
end
elsif windows?
Windows::Lib.dont_inherit file
else
raise Error.new("not sure how to set close-on-exec for #{file.inspect} on #{platform_name.inspect}")
end
end
|
.jruby? ⇒ Boolean
69
70
71
|
# File 'lib/aggkit/childprocess.rb', line 69
def jruby?
platform == :jruby
end
|
.linux? ⇒ Boolean
65
66
67
|
# File 'lib/aggkit/childprocess.rb', line 65
def linux?
os == :linux
end
|
.new(*args) ⇒ Object
Also known as:
build
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/aggkit/childprocess.rb', line 20
def new(*args)
case os
when :macosx, :linux, :solaris, :bsd, :cygwin, :aix
if posix_spawn?
Unix::PosixSpawnProcess.new(args)
elsif jruby?
JRuby::Process.new(args)
else
Unix::ForkExecProcess.new(args)
end
when :windows
Windows::Process.new(args)
else
raise Error.new("unsupported platform #{platform_name.inspect}")
end
end
|
.os ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/aggkit/childprocess.rb', line 103
def os
@os ||= begin
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.new("unknown os: #{host_os.inspect}")
end
end
end
|
47
48
49
50
51
52
53
54
55
|
# File 'lib/aggkit/childprocess.rb', line 47
def platform
if RUBY_PLATFORM == 'java'
:jruby
elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ironruby'
:ironruby
else
os
end
end
|
57
58
59
|
# File 'lib/aggkit/childprocess.rb', line 57
def platform_name
@platform_name ||= "#{arch}-#{os}"
end
|
.posix_spawn? ⇒ Boolean
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/aggkit/childprocess.rb', line 77
def posix_spawn?
enabled = @posix_spawn || %w[1 true].include?(ENV['CHILDPROCESS_POSIX_SPAWN'])
return false unless enabled
require 'ffi'
begin
require "childprocess/unix/platform/#{ChildProcess.platform_name}"
rescue LoadError
raise ChildProcess::MissingPlatformError
end
require 'childprocess/unix/lib'
require 'childprocess/unix/posix_spawn_process'
true
rescue ChildProcess::MissingPlatformError => ex
warn_once ex.message
false
end
|
.unix? ⇒ Boolean
61
62
63
|
# File 'lib/aggkit/childprocess.rb', line 61
def unix?
!windows?
end
|
.windows? ⇒ Boolean
73
74
75
|
# File 'lib/aggkit/childprocess.rb', line 73
def windows?
os == :windows
end
|