fork + exec = spawn

This commit is contained in:
Fabio Rehm 2013-04-23 08:03:29 -03:00
parent 2807f88212
commit 8c884a2e8c
3 changed files with 6 additions and 3 deletions

View file

@ -68,7 +68,7 @@ module Vagrant
redir_cmd = "sudo redir --laddr=127.0.0.1 --lport=#{host} --cport=#{guest} --caddr=#{@container_ip} 2>/dev/null" redir_cmd = "sudo redir --laddr=127.0.0.1 --lport=#{host} --cport=#{guest} --caddr=#{@container_ip} 2>/dev/null"
@logger.debug "Forwarding port with `#{redir_cmd}`" @logger.debug "Forwarding port with `#{redir_cmd}`"
fork { exec redir_cmd } spawn redir_cmd
end end
def store_redir_pid(host_port, redir_pid) def store_redir_pid(host_port, redir_pid)

View file

@ -22,14 +22,14 @@ describe Vagrant::LXC::Action::ForwardPorts do
machine.stub(provider: provider, data_dir: data_dir) machine.stub(provider: provider, data_dir: data_dir)
subject.stub(exec: true) subject.stub(exec: true)
subject.stub(:fork) { |&block| block.call; pid } subject.stub(spawn: pid)
subject.call(env) subject.call(env)
end end
after { FileUtils.rm_rf data_dir.to_s } after { FileUtils.rm_rf data_dir.to_s }
it 'forwards ports using redir' do it 'forwards ports using redir' do
subject.should have_received(:exec).with( subject.should have_received(:spawn).with(
"sudo redir --laddr=127.0.0.1 --lport=#{host_port} --cport=#{guest_port} --caddr=#{container_ip} 2>/dev/null" "sudo redir --laddr=127.0.0.1 --lport=#{host_port} --cport=#{guest_port} --caddr=#{container_ip} 2>/dev/null"
) )
end end

View file

@ -14,6 +14,9 @@ module UnitExampleGroup
Object.any_instance.stub(:fork) { |*args, &block| Object.any_instance.stub(:fork) { |*args, &block|
UnitExampleGroup.prevent_system_calls(*args, &block) UnitExampleGroup.prevent_system_calls(*args, &block)
} }
Object.any_instance.stub(:spawn) { |*args, &block|
UnitExampleGroup.prevent_system_calls(*args, &block)
}
require 'vagrant/util/subprocess' require 'vagrant/util/subprocess'
Vagrant::Util::Subprocess.stub(:execute) { |*args, &block| Vagrant::Util::Subprocess.stub(:execute) { |*args, &block|
UnitExampleGroup.prevent_system_calls(*args, &block) UnitExampleGroup.prevent_system_calls(*args, &block)