samba_dnsupdate: Move to using tmpfile/rename to keep the dns_hosts_file consistent
authorAndrew Bartlett <abartlet@samba.org>
Tue, 25 Sep 2012 23:48:48 +0000 (09:48 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 26 Sep 2012 02:08:26 +0000 (04:08 +0200)
This may be the cause of some of the large failure modes on the build farm.

Andrew Bartlett

source3/Makefile.in
source4/scripting/bin/samba_dnsupdate

index 2ad8eccdb2ae9751da022bd67a9559dd0560c04b..0e72feae794b1d11cdf4947fbf614f5963744392 100644 (file)
@@ -3328,7 +3328,7 @@ test:: all torture timelimit
                VFSLIBDIR="$(builddir)/bin" \
                RUN_FROM_BUILD_FARM="$(RUN_FROM_BUILD_FARM)" \
                SUBUNIT_FORMATTER="$(SUBUNIT_FORMATTER)" \
-               PERL="$(PERL)" PYTHON="$(PYTHON)" \
+               PERL="$(PERL)" PYTHON="$(PYTHON)" PYTHONPATH="$(srcdir)/../bin/python" \
                $(srcdir)/selftest/s3-selftest.sh
 
 test-%:
index d21496ca219341217d9bd5a521ccb56b18a1e730..ab8735648405b413a4425fc85079a32661f267b0 100755 (executable)
@@ -278,10 +278,17 @@ def call_nsupdate(d):
         print "Calling nsupdate for %s" % d
 
     if opts.use_file is not None:
-        wfile = open(opts.use_file, 'a')
-        fcntl.lockf(wfile, fcntl.LOCK_EX)
+        rfile = open(opts.use_file, 'r+')
+        fcntl.lockf(rfile, fcntl.LOCK_EX)
+        (file_dir, file_name) = os.path.split(opts.use_file)
+        (tmp_fd, tmpfile) = tempfile.mkstemp(dir=file_dir, prefix=file_name, suffix="XXXXXX")
+        wfile = os.fdopen(tmp_fd, 'a')
+        rfile.seek(0)
+        for line in rfile:
+            wfile.write(line)
         wfile.write(str(d)+"\n")
-        fcntl.lockf(wfile, fcntl.LOCK_UN)
+        os.rename(tmpfile, opts.use_file)
+        fcntl.lockf(rfile, fcntl.LOCK_UN)
         return
 
     normalised_name = d.name.rstrip('.') + '.'