From 84ef9240b5d8b7d7e4bd7378250ce0fdb6dd07cd Mon Sep 17 00:00:00 2001 From: bwarsaw Date: Fri, 11 May 2001 05:25:07 +0000 Subject: main(): Before we write to the aliases.db file, we must drop an exclusive advisory lock on it, so Postfix doesn't try to read the file while we're updating it. For a discussion of why we have to do this so cruftily, see Mailman/MTA/Postfix.py --- bin/genaliases | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/genaliases b/bin/genaliases index 951c3eabc..b71a74d1b 100644 --- a/bin/genaliases +++ b/bin/genaliases @@ -31,6 +31,7 @@ Options: import sys import getopt import dbhash +import fcntl import paths # path hacking from Mailman import Utils @@ -66,9 +67,13 @@ def main(): # we're doing it. lock = Postfix.makelock() lock.lock() + lockfp = None try: # Overwrite the current file contents, since we're going to be adding - # all new entries. + # all new entries. See the discussion in Mailman/MTA/Postfix.py for + # why we do the locking this way. + lockfp = open(Postfix.DBFILE) + fcntl.flock(lockfp.fileno(), fcntl.LOCK_EX) db = dbhash.open(Postfix.DBFILE, 'n') fp = open(Postfix.TEXTFILE, 'w') for listname in Utils.list_names(): @@ -77,6 +82,9 @@ def main(): db.sync() fp.close() finally: + if lockfp: + fcntl.flock(lockfp.fileno(), fcntl.LOCK_UN) + lockfp.close() lock.unlock(unconditionally=1) -- cgit v1.2.3-70-g09d2