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:
1 parent
5c06aaaa57
commit
baf842cdd4
1 file changed
+13
-2
+13
-2
@@ -1,4 +1,5 @@
|
|||||||
require "foreman"
|
require "foreman"
|
||||||
|
require "shellwords"
|
||||||
|
|
||||||
class Foreman::Process
|
class Foreman::Process
|
||||||
|
|
||||||
@@ -54,8 +55,8 @@ class Foreman::Process
|
|||||||
end
|
end
|
||||||
elsif Foreman.jruby_18? || Foreman.ruby_18?
|
elsif Foreman.jruby_18? || Foreman.ruby_18?
|
||||||
require "posix/spawn"
|
require "posix/spawn"
|
||||||
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
|
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{expanded_command(env)}"
|
||||||
POSIX::Spawn.spawn env, wrapped_command, :out => output, :err => output
|
POSIX::Spawn.spawn(*spawn_args(env, wrapped_command.shellsplit, {:out => output, :err => output}))
|
||||||
else
|
else
|
||||||
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
|
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
|
||||||
Process.spawn env, wrapped_command, :out => output, :err => output
|
Process.spawn env, wrapped_command, :out => output, :err => output
|
||||||
@@ -114,4 +115,14 @@ class Foreman::Process
|
|||||||
File.expand_path(@options[:cwd] || ".")
|
File.expand_path(@options[:cwd] || ".")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def spawn_args(env, argv, options)
|
||||||
|
args = []
|
||||||
|
args << env
|
||||||
|
args += argv
|
||||||
|
args << options
|
||||||
|
args
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user