Browse Source

bitbake: bitbake-worker child process create group before registering SIGTERM handler

The bitbake-worker child on the SIGTERM signal handling send the SIGTERM to all
processes in it's process group. In cases when the bitbake-worker child got
SIGTERM after registering own SIGTERM handler and before the os.setsid() call
it can send SIGTERM to unwanted processes.

In the worst case during SIGTERM processing the bitbake-worker child can be in
the group of the process that started BitBake itself. As a result it can kill
processes that not related to BitBake at all.

(Bitbake rev: b51877cbb8a7c713aa2bcec8354ec66e2f3dad51)

Signed-off-by: Ivan Efimov <i.efimov@inango-systems.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Ivan Efimov 5 years ago
parent
commit
532f2df770
1 changed files with 5 additions and 3 deletions
  1. 5 3
      bitbake/bin/bitbake-worker

+ 5 - 3
bitbake/bin/bitbake-worker

@@ -192,9 +192,6 @@ def fork_off_task(cfg, data, databuilder, workerdata, fn, task, taskname, append
             global worker_pipe_lock
             global worker_pipe_lock
             pipein.close()
             pipein.close()
 
 
-            signal.signal(signal.SIGTERM, sigterm_handler)
-            # Let SIGHUP exit as SIGTERM
-            signal.signal(signal.SIGHUP, sigterm_handler)
             bb.utils.signal_on_parent_exit("SIGTERM")
             bb.utils.signal_on_parent_exit("SIGTERM")
 
 
             # Save out the PID so that the event can include it the
             # Save out the PID so that the event can include it the
@@ -209,6 +206,11 @@ def fork_off_task(cfg, data, databuilder, workerdata, fn, task, taskname, append
             # This ensures signals sent to the controlling terminal like Ctrl+C
             # This ensures signals sent to the controlling terminal like Ctrl+C
             # don't stop the child processes.
             # don't stop the child processes.
             os.setsid()
             os.setsid()
+
+            signal.signal(signal.SIGTERM, sigterm_handler)
+            # Let SIGHUP exit as SIGTERM
+            signal.signal(signal.SIGHUP, sigterm_handler)
+
             # No stdin
             # No stdin
             newsi = os.open(os.devnull, os.O_RDWR)
             newsi = os.open(os.devnull, os.O_RDWR)
             os.dup2(newsi, sys.stdin.fileno())
             os.dup2(newsi, sys.stdin.fileno())