From 0b1fffc6e3113dbec2103a3318aa32f6255e5f95 Mon Sep 17 00:00:00 2001 From: guerremdq Date: Tue, 29 Apr 2014 00:02:16 -0300 Subject: [PATCH] clean redir pid with sudo only if port is < than 1024 --- lib/vagrant-lxc/action/clear_forwarded_ports.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/vagrant-lxc/action/clear_forwarded_ports.rb b/lib/vagrant-lxc/action/clear_forwarded_ports.rb index 52d4450..bf6d1b3 100644 --- a/lib/vagrant-lxc/action/clear_forwarded_ports.rb +++ b/lib/vagrant-lxc/action/clear_forwarded_ports.rb @@ -13,9 +13,13 @@ module Vagrant if redir_pids.any? env[:ui].info I18n.t("vagrant.actions.vm.clear_forward_ports.deleting") redir_pids.each do |pid| - next unless is_redir_pid?(pid) - @logger.debug "Killing pid #{pid}" - system "sudo pkill -TERM -P #{pid}" + next unless is_redir_pid?(pid[0]) + @logger.debug "Killing pid #{pid[0]}" + if pid[1] + system "sudo pkill -TERM -P #{pid[0]}" + else + system "pkill -TERM -P #{pid[0]}" + end end @logger.info "Removing redir pids files" @@ -31,7 +35,9 @@ module Vagrant def redir_pids @redir_pids = Dir[@env[:machine].data_dir.join('pids').to_s + "/redir_*.pid"].map do |file| - File.read(file).strip.chomp + port_number = file.split(/[^\d]/).join + privileged_port = true if Integer(port_number) > 1024 + a = [ File.read(file).strip.chomp , privileged_port ] end end