Skip to content

Commit

Permalink
Do not leave /etc/hosts open
Browse files Browse the repository at this point in the history
  • Loading branch information
DirtYiCE committed Mar 15, 2011
1 parent 46304d4 commit b01d416
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/cool.io/dns_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit b01d416

Please sign in to comment.