From b021992106c6b5ba02b825afa7dcc422b135b59b Mon Sep 17 00:00:00 2001 From: Ivan Efimov Date: Tue, 5 Nov 2019 19:07:03 +0500 Subject: 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: b7483a7738daf69902ef590a8144a557576bbce0) Signed-off-by: Ivan Efimov Signed-off-by: Richard Purdie --- bitbake/bin/bitbake-worker | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bitbake/bin/bitbake-worker b/bitbake/bin/bitbake-worker index f63f060c57..c1df3ecd9f 100755 --- a/bitbake/bin/bitbake-worker +++ b/bitbake/bin/bitbake-worker @@ -195,9 +195,6 @@ def fork_off_task(cfg, data, databuilder, workerdata, fn, task, taskname, taskha global worker_pipe_lock 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") # Save out the PID so that the event can include it the @@ -212,6 +209,11 @@ def fork_off_task(cfg, data, databuilder, workerdata, fn, task, taskname, taskha # This ensures signals sent to the controlling terminal like Ctrl+C # don't stop the child processes. os.setsid() + + signal.signal(signal.SIGTERM, sigterm_handler) + # Let SIGHUP exit as SIGTERM + signal.signal(signal.SIGHUP, sigterm_handler) + # No stdin newsi = os.open(os.devnull, os.O_RDWR) os.dup2(newsi, sys.stdin.fileno()) -- cgit v1.2.3-54-g00ecf