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

login
register
mail settings
Submitter Richard Purdie
Date March 9, 2014, 4:59 p.m.
Message ID <1394384359.7883.6.camel@ted>
Download mbox | patch
Permalink /patch/68327/
State New
Headers show

Comments

Richard Purdie - March 9, 2014, 4:59 p.m.
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@linuxfoundation.org>
---

Patch

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)