From ce1897a31afb5a14997bc3d2f459b90d43eecb7d Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Fri, 4 Sep 2020 15:38:41 +0100 Subject: server/process: Ensure we don't keep looping if some other server is started Showing "leftover process" messages when a new server has started and is being used by some UI is horrible. Compare the PID data from the lockfile to avoid this (and the ton of confusing log data it generates). Also, move the time.sleep() call to be after the first lock attempt, which reduces noise in the logs significantly. Signed-off-by: Richard Purdie --- lib/bb/server/process.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/bb/server/process.py b/lib/bb/server/process.py index f794505fd..83c3e6b44 100644 --- a/lib/bb/server/process.py +++ b/lib/bb/server/process.py @@ -266,6 +266,17 @@ class ProcessServer(): # Finally release the lockfile but warn about other processes holding it open lock = self.bitbake_lock lockfile = self.bitbake_lock_name + + def get_lock_contents(lockfile): + try: + with open(lockfile, "r") as f: + return f.readlines() + except FileNotFoundError: + return None + + lockcontents = get_lock_contents(lockfile) + serverlog("Original lockfile contents: " + str(lockcontents)) + lock.close() lock = None @@ -273,14 +284,22 @@ class ProcessServer(): i = 0 lock = None while not lock and i < 30: - time.sleep(0.1) lock = bb.utils.lockfile(lockfile, shared=False, retry=False, block=False) + if not lock: + newlockcontents = get_lock_contents(lockfile) + if newlockcontents != lockcontents: + # A new server was started, the lockfile contents changed, we can exit + serverlog("Lockfile now contains different contents, exiting: " + str(newlockcontents)) + return + time.sleep(0.1) i += 1 if lock: # We hold the lock so we can remove the file (hide stale pid data) # via unlockfile. bb.utils.unlockfile(lock) + serverlog("Exiting as we could obtain the lock") return + if not lock: # Some systems may not have lsof available procs = None -- cgit 1.2.3-korg