Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
action/clear_forwarded_ports: Fix privileged port detection and simpl…
Browse files Browse the repository at this point in the history
…ify code [GH-259]
  • Loading branch information
fgrehm committed May 4, 2014
1 parent 84bdb5c commit a0fe2f9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions lib/vagrant-lxc/action/clear_forwarded_ports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ def call(env)

def redir_pids
@redir_pids = Dir[@env[:machine].data_dir.join('pids').to_s + "/redir_*.pid"].map do |file|
port_number = file.split(/[^\d]/).join
privileged_port = true if Integer(port_number) > 1024
a = [ File.read(file).strip.chomp , privileged_port ]
port_number = File.basename(file).split(/[^\d]/).join
[ File.read(file).strip.chomp , Integer(port_number) <= 1024 ]
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/unit/action/clear_forwarded_ports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@

context 'with a valid redir pid' 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

context 'with an invalid pid' do
let(:pid_cmd) { 'sudo ls' }

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

0 comments on commit a0fe2f9

Please sign in to comment.