summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/cooker.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2015-07-31 10:16:33 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-08-01 07:34:09 +0100
commit4c2f28bf482c2abda937b21217fc41d71f037166 (patch)
tree88d2a9793a671d2b0b575ab6c65a8ca0751b5d10 /bitbake/lib/bb/cooker.py
parent18dfdb08403856c106169a969ce9080c60b7cb51 (diff)
downloadpoky-4c2f28bf482c2abda937b21217fc41d71f037166.tar.gz
bitbake: cooker: properly fix bitbake.lock handling
If the PR server or indeed any other child process takes some time to exit (which it sometimes does when saving its database), it can end up holding bitbake.lock after the UI exits, which led to errors if you ran bitbake commands successively - we saw this when running the PR server oe-selftest tests in OE-Core. The recent attempt to fix this wasn't quite right and ended up breaking memory resident bitbake. This time we close the lock file when cooker shuts down (inside the UI process) instead of unlocking it, and this is done in the cooker code rather than the actual UI code so it doesn't matter which UI is in use. Additionally we report that we're waiting for the lock to be released, using lsof or fuser if available to list the processes with the lock open. The 'magic' in the locking is due to all spawned subprocesses of bitbake holding an open file descriptor to the bitbake.lock. It is automatically unlocked when all those fds close the file (as all the processes terminate). We close the UI copy of the lock explicitly, then close the server process copy, any remaining open copy is therefore some proess exiting. (The reproducer for the problem is to set PRSERV_HOST = "localhost:0" and add a call to time.sleep(20) after self.server_close() in lib/prserv/serv.py, then run "bitbake -p; bitbake -p" ). Cleanup work done by Paul Eggleton <paul.eggleton@linux.intel.com>. This reverts bitbake commit 69ecd15aece54753154950c55d7af42f85ad8606 and e97a9f1528d77503b5c93e48e3de9933fbb9f3cd. (Bitbake rev: a29780bd43f74b7326fe788dbd65177b86806fcf) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/cooker.py')
-rw-r--r--bitbake/lib/bb/cooker.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
index 46e5560e83..52b81be7b6 100644
--- a/bitbake/lib/bb/cooker.py
+++ b/bitbake/lib/bb/cooker.py
@@ -38,6 +38,8 @@ import bb, bb.exceptions, bb.command
38from bb import utils, data, parse, event, cache, providers, taskdata, runqueue, build 38from bb import utils, data, parse, event, cache, providers, taskdata, runqueue, build
39import Queue 39import Queue
40import signal 40import signal
41import subprocess
42import errno
41import prserv.serv 43import prserv.serv
42import pyinotify 44import pyinotify
43 45
@@ -1532,6 +1534,34 @@ class BBCooker:
1532 def post_serve(self): 1534 def post_serve(self):
1533 prserv.serv.auto_shutdown(self.data) 1535 prserv.serv.auto_shutdown(self.data)
1534 bb.event.fire(CookerExit(), self.expanded_data) 1536 bb.event.fire(CookerExit(), self.expanded_data)
1537 lockfile = self.lock.name
1538 self.lock.close()
1539 self.lock = None
1540
1541 while not self.lock:
1542 with bb.utils.timeout(3):
1543 self.lock = bb.utils.lockfile(lockfile, shared=False, retry=False, block=True)
1544 if not self.lock:
1545 # Some systems may not have lsof available
1546 procs = None
1547 try:
1548 procs = subprocess.check_output(["lsof", '-w', lockfile], stderr=subprocess.STDOUT)
1549 except OSError as e:
1550 if e.errno != errno.ENOENT:
1551 raise
1552 if procs is None:
1553 # Fall back to fuser if lsof is unavailable
1554 try:
1555 procs = subprocess.check_output(["fuser", '-v', lockfile], stderr=subprocess.STDOUT)
1556 except OSError as e:
1557 if e.errno != errno.ENOENT:
1558 raise
1559
1560 msg = "Delaying shutdown due to active processes which appear to be holding bitbake.lock"
1561 if procs:
1562 msg += ":\n%s" % str(procs)
1563 print(msg)
1564
1535 1565
1536 def shutdown(self, force = False): 1566 def shutdown(self, force = False):
1537 if force: 1567 if force: