aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2020-09-04 15:38:41 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-09-05 11:45:10 +0100
commitce1897a31afb5a14997bc3d2f459b90d43eecb7d (patch)
treec940904d3e2d595a9c8f22d384294b827752a29a
parentffdb3d3fa690c35e9a96fc451a5811f5131276f3 (diff)
downloadbitbake-ce1897a31afb5a14997bc3d2f459b90d43eecb7d.tar.gz
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 <richard.purdie@linuxfoundation.org>
-rw-r--r--lib/bb/server/process.py21
1 files changed, 20 insertions, 1 deletions
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