From a7275aab03b853242fdc3e7a1097c04d73416632 Mon Sep 17 00:00:00 2001 From: Brian Pitts Date: Thu, 30 Jan 2014 18:13:38 -0600 Subject: [PATCH] Make SSH for forwarded ports write to /dev/null If ssh inherits stdout from vagrant, then when you pipe vagrants output to another program ssh will also use that pipe. The receiving program will hang waiting on ssh to exit. To make reasoning about things easier, I have ruby start ssh directly instead of via a shell. Then I have spawn set stdin/stdout to /dev/null. --- lib/vagrant-libvirt/action/forward_ports.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/vagrant-libvirt/action/forward_ports.rb b/lib/vagrant-libvirt/action/forward_ports.rb index 165b69c..f976361 100644 --- a/lib/vagrant-libvirt/action/forward_ports.rb +++ b/lib/vagrant-libvirt/action/forward_ports.rb @@ -82,11 +82,12 @@ module VagrantPlugins -L #{host_ip}:#{host_port}:#{guest_ip}:#{guest_port} -N ).join(' ') - ssh_cmd = "ssh $(vagrant ssh-config #{machine}"\ - "| awk '{print \" -o \"$1\"=\"$2}') #{params} 2>/dev/null" + # TODO get options without shelling out + options = `vagrant ssh-config #{machine} | awk '{printf " -o "$1"="$2}'` + ssh_cmd = "ssh #{options} #{params}" @logger.debug "Forwarding port with `#{ssh_cmd}`" - spawn ssh_cmd + spawn(ssh_cmd, [:out, :err] => '/dev/null') end def store_ssh_pid(host_port, ssh_pid) @@ -124,7 +125,7 @@ module VagrantPlugins ssh_pids.each do |pid| next unless ssh_pid?(pid) @logger.debug "Killing pid #{pid}" - system "pkill -TERM -P #{pid}" + system "kill #{pid}" end @logger.info 'Removing ssh pid files'