The wrapped_command has spaces which triggers Ruby to fork a system shell (with /bin/sh -c). This causes orphaned processes on some systems (i.e. Linux). Fix this by splitting the command using String#shellsplit and using ruby's splat operator (*) to pass discrete arguments to spawn.
This commit is contained in:
+13
-2
@@ -1,4 +1,5 @@
|
||||
require "foreman"
|
||||
require "shellwords"
|
||||
|
||||
class Foreman::Process
|
||||
|
||||
@@ -54,8 +55,8 @@ class Foreman::Process
|
||||
end
|
||||
elsif Foreman.jruby_18? || Foreman.ruby_18?
|
||||
require "posix/spawn"
|
||||
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
|
||||
POSIX::Spawn.spawn env, wrapped_command, :out => output, :err => output
|
||||
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{expanded_command(env)}"
|
||||
POSIX::Spawn.spawn(*spawn_args(env, wrapped_command.shellsplit, {:out => output, :err => output}))
|
||||
else
|
||||
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
|
||||
Process.spawn env, wrapped_command, :out => output, :err => output
|
||||
@@ -114,4 +115,14 @@ class Foreman::Process
|
||||
File.expand_path(@options[:cwd] || ".")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def spawn_args(env, argv, options)
|
||||
args = []
|
||||
args << env
|
||||
args += argv
|
||||
args << options
|
||||
args
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user