]> git.decadent.org.uk Git - dak.git/commitdiff
daklib/daklog.py: acquire an advisory lock when writing to file
authorAnsgar Burchardt <ansgar@debian.org>
Sun, 14 Jun 2015 10:25:56 +0000 (12:25 +0200)
committerAnsgar Burchardt <ansgar@debian.org>
Sun, 14 Jun 2015 10:25:56 +0000 (12:25 +0200)
daklib/daklog.py

index 05ca9b1adaab9770ae6048956b1df1fda00a5e13..a698cbc53fc5d754fb3ec2392aab73b299c3e1eb 100644 (file)
@@ -24,6 +24,7 @@ Logging functions
 
 ################################################################################
 
+import fcntl
 import os
 import pwd
 import time
@@ -80,13 +81,14 @@ class Logger(object):
         details.insert(0, timestamp)
         # Force the contents of the list to be string.join-able
         details = [ str(i) for i in details ]
+        fcntl.lockf(self.logfile, fcntl.LOCK_EX)
         # Write out the log in TSV
         self.logfile.write("|".join(details)+'\n')
         # Flush the output to enable tail-ing
         self.logfile.flush()
+        fcntl.lockf(self.logfile, fcntl.LOCK_UN)
 
     def close (self):
         "Close a Logger object"
         self.log(["program end"])
-        self.logfile.flush()
         self.logfile.close()