From 4ed5eb477a27e18a4d904c6675caf6aa0446b30b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 9 Nov 2011 23:53:09 +1100 Subject: [PATCH] autotest: use a lock file this ensures we don't run two copies of the tests at once --- Tools/autotest/autotest.py | 6 ++++++ Tools/autotest/util.py | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/Tools/autotest/autotest.py b/Tools/autotest/autotest.py index bad56d73b2..de2870ff41 100755 --- a/Tools/autotest/autotest.py +++ b/Tools/autotest/autotest.py @@ -243,6 +243,12 @@ def run_tests(steps): return passed + +lck = util.lock_file(util.reltopdir('../buildlogs/autotest.lck')) +if lck is None: + print("autotest is locked - exiting") + sys.exit(0) + try: if not run_tests(steps): sys.exit(1) diff --git a/Tools/autotest/util.py b/Tools/autotest/util.py index d27943fe22..df721ae68e 100644 --- a/Tools/autotest/util.py +++ b/Tools/autotest/util.py @@ -160,3 +160,13 @@ def loadfile(fname): r = f.read() f.close() return r + +def lock_file(fname): + '''lock a file''' + import fcntl + f = open(fname, mode='w') + try: + fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB) + except Exception: + return None + return f