From baf842cdd4a0addf13492423173ae60966e0b5cd Mon Sep 17 00:00:00 2001 From: Klaas Jan Wierenga Date: Thu, 2 May 2013 15:06:38 +0200 Subject: [PATCH] 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. --- lib/foreman/process.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/foreman/process.rb b/lib/foreman/process.rb index 39cb4c5..c2838aa 100644 --- a/lib/foreman/process.rb +++ b/lib/foreman/process.rb @@ -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