summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/cooker.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2017-07-18 22:28:40 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-07-21 08:41:11 +0100
commit4602408c69132315c3784718fe4ce155b12464cf (patch)
tree2262f6d8b5e89930b4da4efd72e226ae8f740611 /bitbake/lib/bb/cooker.py
parent21a19e0e0bf1b39969f6f2ec37a5784d0069715b (diff)
downloadpoky-4602408c69132315c3784718fe4ce155b12464cf.tar.gz
bitbake: server: Rework the server API so process and xmlrpc servers coexist
This changes the way bitbake server works quite radically. Now, the server is always a process based server with the option of starting an XMLRPC listener on a specific inferface/port. Behind the scenes this is done with a "bitbake.sock" file alongside the bitbake.lock file. If we can obtain the lock, we know we need to start a server. The server always listens on the socket and UIs can then connect to this. UIs connect by sending a set of three file descriptors over the domain socket, one for sending commands, one for receiving command results and the other for receiving events. These changes meant we can throw away all the horrid server abstraction code, the plugable transport option to bitbake and the code becomes much more readable and debuggable. It also likely removes a ton of ways you could hang the UI/cooker in weird ways due to all the race conditions that existed with previous processes. Changes: * The foreground option for bitbake-server was dropped. Just tail the log if you really want this, the codepaths were complicated enough without adding one for this. * BBSERVER="autodetect" was dropped. The server will autostart and autoconnect in process mode. You have to specify an xmlrpc server address since that can't be autodetected. I can't see a use case for autodetect now. * The transport/servetype option to bitbake was dropped. * A BB_SERVER_TIMEOUT variable is added which allows the server to stay resident for a period of time after the last client disconnects before unloading. This is used if the -T/--idle-timeout option is not passed to bitbake. This change is invasive and may well introduce new issues however I believe the codebase is in a much better position for further development and debugging. (Bitbake rev: 72a3dbe13a23588e24c0baca6d58c35cdeba3f63) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/cooker.py')
-rw-r--r--bitbake/lib/bb/cooker.py58
1 files changed, 1 insertions, 57 deletions
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
index b1311bb170..e27763ecab 100644
--- a/bitbake/lib/bb/cooker.py
+++ b/bitbake/lib/bb/cooker.py
@@ -215,19 +215,6 @@ class BBCooker:
215 215
216 self.configuration.server_register_idlecallback(_process_inotify_updates, [self.confignotifier, self.notifier]) 216 self.configuration.server_register_idlecallback(_process_inotify_updates, [self.confignotifier, self.notifier])
217 217
218 # Take a lock so only one copy of bitbake can run against a given build
219 # directory at a time
220 if not self.lockBitbake():
221 bb.fatal("Only one copy of bitbake should be run against a build directory")
222 try:
223 self.lock.seek(0)
224 self.lock.truncate()
225 if len(configuration.interface) >= 2:
226 self.lock.write("%s:%s\n" % (configuration.interface[0], configuration.interface[1]));
227 self.lock.flush()
228 except:
229 pass
230
231 # TOSTOP must not be set or our children will hang when they output 218 # TOSTOP must not be set or our children will hang when they output
232 try: 219 try:
233 fd = sys.stdout.fileno() 220 fd = sys.stdout.fileno()
@@ -1557,33 +1544,6 @@ class BBCooker:
1557 def post_serve(self): 1544 def post_serve(self):
1558 prserv.serv.auto_shutdown(self.data) 1545 prserv.serv.auto_shutdown(self.data)
1559 bb.event.fire(CookerExit(), self.data) 1546 bb.event.fire(CookerExit(), self.data)
1560 lockfile = self.lock.name
1561 self.lock.close()
1562 self.lock = None
1563
1564 while not self.lock:
1565 with bb.utils.timeout(3):
1566 self.lock = bb.utils.lockfile(lockfile, shared=False, retry=False, block=True)
1567 if not self.lock:
1568 # Some systems may not have lsof available
1569 procs = None
1570 try:
1571 procs = subprocess.check_output(["lsof", '-w', lockfile], stderr=subprocess.STDOUT)
1572 except OSError as e:
1573 if e.errno != errno.ENOENT:
1574 raise
1575 if procs is None:
1576 # Fall back to fuser if lsof is unavailable
1577 try:
1578 procs = subprocess.check_output(["fuser", '-v', lockfile], stderr=subprocess.STDOUT)
1579 except OSError as e:
1580 if e.errno != errno.ENOENT:
1581 raise
1582
1583 msg = "Delaying shutdown due to active processes which appear to be holding bitbake.lock"
1584 if procs:
1585 msg += ":\n%s" % str(procs)
1586 print(msg)
1587 1547
1588 1548
1589 def shutdown(self, force = False): 1549 def shutdown(self, force = False):
@@ -1605,23 +1565,7 @@ class BBCooker:
1605 1565
1606 def clientComplete(self): 1566 def clientComplete(self):
1607 """Called when the client is done using the server""" 1567 """Called when the client is done using the server"""
1608 if self.configuration.server_only: 1568 self.finishcommand()
1609 self.finishcommand()
1610 else:
1611 self.shutdown(True)
1612
1613 def lockBitbake(self):
1614 if not hasattr(self, 'lock'):
1615 self.lock = None
1616 if self.data:
1617 lockfile = self.data.expand("${TOPDIR}/bitbake.lock")
1618 if lockfile:
1619 self.lock = bb.utils.lockfile(lockfile, False, False)
1620 return self.lock
1621
1622 def unlockBitbake(self):
1623 if hasattr(self, 'lock') and self.lock:
1624 bb.utils.unlockfile(self.lock)
1625 1569
1626def server_main(cooker, func, *args): 1570def server_main(cooker, func, *args):
1627 cooker.pre_serve() 1571 cooker.pre_serve()