import ipaddress
import logging
import logging.handlers
+import os
import re
import signal
+import stat
import subprocess
+import tempfile
import inotify.adapters
line = line.rstrip()
try:
- enabled, ipaddr, hostname, domainname = line.split(",")
+ enabled, ipaddr, hostname, domainname, generateptr = line.split(",")
except:
log.warning("Could not parse line: %s" % line)
continue
self._cached_leases.append(l)
def write_dhcp_leases(self, leases):
- with open(self.path, "w") as f:
+ with tempfile.NamedTemporaryFile(mode="w", delete=False) as f:
+ filename = f.name
+
for l in leases:
for rr in l.rrset:
f.write("local-data: \"%s\"\n" % " ".join(rr))
+ # Make file readable for everyone
+ os.fchmod(f.fileno(), stat.S_IRUSR|stat.S_IWUSR|stat.S_IRGRP|stat.S_IROTH)
+
+ os.rename(filename, self.path)
+
def _control(self, *args):
command = ["unbound-control"]
command.extend(args)