action/clear_forwarded_ports: Fix privileged port detection and simplify code [GH-259]
This commit is contained in:
parent
84bdb5cb22
commit
a0fe2f9cf0
2 changed files with 4 additions and 5 deletions
|
@ -35,9 +35,8 @@ module Vagrant
|
||||||
|
|
||||||
def redir_pids
|
def redir_pids
|
||||||
@redir_pids = Dir[@env[:machine].data_dir.join('pids').to_s + "/redir_*.pid"].map do |file|
|
@redir_pids = Dir[@env[:machine].data_dir.join('pids').to_s + "/redir_*.pid"].map do |file|
|
||||||
port_number = file.split(/[^\d]/).join
|
port_number = File.basename(file).split(/[^\d]/).join
|
||||||
privileged_port = true if Integer(port_number) > 1024
|
[ File.read(file).strip.chomp , Integer(port_number) <= 1024 ]
|
||||||
a = [ File.read(file).strip.chomp , privileged_port ]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ describe Vagrant::LXC::Action::ClearForwardedPorts do
|
||||||
|
|
||||||
context 'with a valid redir pid' do
|
context 'with a valid redir pid' do
|
||||||
it 'kills known processes' do
|
it 'kills known processes' do
|
||||||
expect(subject).to have_received(:system).with("sudo pkill -TERM -P #{pid}")
|
expect(subject).to have_received(:system).with("pkill -TERM -P #{pid}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ describe Vagrant::LXC::Action::ClearForwardedPorts do
|
||||||
let(:pid_cmd) { 'sudo ls' }
|
let(:pid_cmd) { 'sudo ls' }
|
||||||
|
|
||||||
it 'does not kill the process' do
|
it 'does not kill the process' do
|
||||||
expect(subject).not_to have_received(:system).with("sudo pkill -TERM -P #{pid}")
|
expect(subject).not_to have_received(:system).with("pkill -TERM -P #{pid}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue