From 11698e027d71967153b272bf34996bee8f3908e5 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Sat, 14 Jan 2023 13:35:08 +0000 Subject: bitbake: server/process: Improve lockfile handling at exit If memory resident bitbake is active and the build directory is renamed upon build completion, several bad things can happen: * the old build directory could be re-created to contain a lockfile leaving an empty directory behind * a lockfile for a new build could be found and attempt to be locked This patch avoids creating an empty directory (not perfectly, but should work in the majority of cases - an empty directory is cosmetic). It also now compares the lock file contents to it's own pid and just exits if it doesn't match, it is clearly then belonging to some new process. This will be combined with bitbake shutdown calls on the autobuilder to ensure "saved" build directories, or build directories being deleted by clobberdir don't do strange things. (Bitbake rev: b986eac18b6a8bf633f5ef15f32f68de4c86173b) Signed-off-by: Richard Purdie --- bitbake/lib/bb/server/process.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'bitbake/lib/bb/server') diff --git a/bitbake/lib/bb/server/process.py b/bitbake/lib/bb/server/process.py index 529196b78c..8d12f00bd4 100644 --- a/bitbake/lib/bb/server/process.py +++ b/bitbake/lib/bb/server/process.py @@ -361,20 +361,21 @@ class ProcessServer(): except FileNotFoundError: return None - lockcontents = get_lock_contents(lockfile) - serverlog("Original lockfile contents: " + str(lockcontents)) - lock.close() lock = None while not lock: i = 0 lock = None + if not os.path.exists(os.path.basename(lockfile)): + serverlog("Lockfile directory gone, exiting.") + return + while not lock and i < 30: lock = bb.utils.lockfile(lockfile, shared=False, retry=False, block=False) if not lock: newlockcontents = get_lock_contents(lockfile) - if newlockcontents != lockcontents: + if not newlockcontents.startswith([os.getpid() + "\n", os.getpid() + " "]): # A new server was started, the lockfile contents changed, we can exit serverlog("Lockfile now contains different contents, exiting: " + str(newlockcontents)) return -- cgit v1.2.3-54-g00ecf