[bitbake-devel] [PATCH] bitbake-worker: Gracefully handle SIGTERM

Richard Purdie richard.purdie at linuxfoundation.org
Sun Mar 9 16:59:19 UTC 2014


Currently if bitbake-worker handles a SIGTERM, it leaves the child
processes to complete or hang. It shouldn't do this so hook the SIGTERM
event and gracefully shutdown any children.

Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
diff --git a/bitbake/bin/bitbake-worker b/bitbake/bin/bitbake-worker
index bc13b4f..c173dbe 100755
--- a/bitbake/bin/bitbake-worker
+++ b/bitbake/bin/bitbake-worker
@@ -242,6 +242,14 @@ class BitbakeWorker(object):
         self.build_pids = {}
         self.build_pipes = {}
     
+        signal.signal(signal.SIGTERM, self.sigterm_exception)
+
+    def sigterm_exception(self, signum, stackframe):
+        bb.warn("Worker recieved SIGTERM, shutting down...")
+        self.handle_finishnow(None)
+        signal.signal(signal.SIGTERM, signal.SIG_DFL)
+        os.kill(os.getpid(), signal.SIGTERM)
+
     def serve(self):        
         while True:
             (ready, _, _) = select.select([self.input] + [i.input for i in self.build_pipes.values()], [] , [], 1)





More information about the bitbake-devel mailing list