Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Do not leave /etc/hosts open

  • Loading branch information...
commit b01d4169805b5326de472eaa96a64f9e85253ac7 1 parent 46304d4
@DirtYiCE DirtYiCE authored
Showing with 6 additions and 4 deletions.
  1. +6 −4 lib/cool.io/dns_resolver.rb
View
10 lib/cool.io/dns_resolver.rb
@@ -44,10 +44,12 @@ class DNSResolver < IOWatcher
# Query /etc/hosts (or the specified hostfile) for the given host
def self.hosts(host, hostfile = HOSTS)
hosts = {}
- File.open(hostfile).each_line do |host_entry|
- entries = host_entry.gsub(/#.*$/, '').gsub(/\s+/, ' ').split(' ')
- addr = entries.shift
- entries.each { |e| hosts[e] ||= addr }
+ File.open(hostfile) do |f|
+ f.each_line do |host_entry|
+ entries = host_entry.gsub(/#.*$/, '').gsub(/\s+/, ' ').split(' ')
+ addr = entries.shift
+ entries.each { |e| hosts[e] ||= addr }
+ end
end
hosts[host]
Please sign in to comment.
Something went wrong with that request. Please try again.