Skip to content

Commit

Permalink
Make linux dns setting more reliable (related to issue #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwgh committed Nov 7, 2012
1 parent 6928934 commit fcd2132
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions srdns.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,22 @@ def set_dns(self, dnsserver):
# Go through and find the first nameserver line, and replace
# it with our modified one
replaced = False
for i, line in enumerate(lines):
newlines = []
for line in lines:
if line.startswith('nameserver '):
lines[i] = nsline
replaced = True
break
if not replaced:
newlines.append(nsline)
replaced = True
else:
newlines.append(line)

# If we didn't already have a nameserver line, let's add one now
if not replaced:
lines.append(nsline)
newlines.append(nsline)

# And save off the new resolv.conf
with file(self.resolvconf, 'w') as f:
f.write('\n'.join(lines))
f.write('\n'.join(newlines))

def daemon():
sysname = platform.system()
Expand Down

0 comments on commit fcd2132

Please sign in to comment.