Skip to contentSkip to conversation

bitbake-worker: Gracefully handle SIGTERM

PATCH New Richard Purdie 1 participant 1 message Mar 9, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bitbake-worker: Gracefully handle SIGTERM

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.

---

bitbake/bin/bitbake-worker +8 -0
index bc13b4f..c173dbe 100755
@@ -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)