Fork-and-wait SSH on Mac OS X 10.5 [closes GH-51]
This commit is contained in:
parent
9f6b6435be
commit
d845e73138
|
@ -18,7 +18,7 @@ module Vagrant
|
|||
# of options which override the configuration values.
|
||||
def connect(opts={})
|
||||
if Mario::Platform.windows?
|
||||
error_and_exit(:ssh_unavailable_windows,
|
||||
error_and_exit(:ssh_unavailable_windows,
|
||||
:key_path => env.config.ssh.private_key_path,
|
||||
:ssh_port => port(opts))
|
||||
end
|
||||
|
@ -29,7 +29,14 @@ module Vagrant
|
|||
end
|
||||
|
||||
check_key_permissions(options[:private_key_path])
|
||||
Kernel.exec "ssh -p #{port(opts)} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i #{options[:private_key_path]} #{options[:username]}@#{options[:host]}".strip
|
||||
|
||||
# Some hackery going on here. On Mac OS X Leopard (10.5), exec fails
|
||||
# (GH-51). As a workaround, we fork and wait. On all other platforms,
|
||||
# we simply exec.
|
||||
pid = nil
|
||||
pid = fork if Util::Platform.leopard?
|
||||
Kernel.exec "ssh -p #{port(opts)} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i #{options[:private_key_path]} #{options[:username]}@#{options[:host]}".strip if pid.nil?
|
||||
Process.wait(pid) if pid
|
||||
end
|
||||
|
||||
# Opens an SSH connection to this environment's virtual machine and yields
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
module Vagrant
|
||||
module Util
|
||||
# This class just contains some platform checking code.
|
||||
class Platform
|
||||
class <<self
|
||||
def leopard?
|
||||
RUBY_PLATFORM.downcase.include?("darwin9")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -15,6 +15,8 @@ class SshTest < Test::Unit::TestCase
|
|||
@ssh.stubs(:check_key_permissions)
|
||||
@ssh.stubs(:error_and_exit)
|
||||
Kernel.stubs(:exec)
|
||||
|
||||
Vagrant::Util::Platform.stubs(:leopard?).returns(false)
|
||||
end
|
||||
|
||||
should "check key permissions prior to exec" do
|
||||
|
@ -38,7 +40,21 @@ class SshTest < Test::Unit::TestCase
|
|||
@ssh.connect(args)
|
||||
end
|
||||
|
||||
context "cheching windows" do
|
||||
context "on leopard" do
|
||||
setup do
|
||||
Vagrant::Util::Platform.stubs(:leopard?).returns(true)
|
||||
end
|
||||
|
||||
should "fork, exec, and wait" do
|
||||
pid = mock("pid")
|
||||
@ssh.expects(:fork).once.returns(pid)
|
||||
Process.expects(:wait).with(pid)
|
||||
|
||||
@ssh.connect
|
||||
end
|
||||
end
|
||||
|
||||
context "checking windows" do
|
||||
should "error and exit if the platform is windows" do
|
||||
Mario::Platform.expects(:windows?).returns(true)
|
||||
@ssh.expects(:error_and_exit).with do |error_name, opts|
|
||||
|
|
Loading…
Reference in New Issue