diff options
author | Jürg Billeter <j@bitron.ch> | 2020-03-03 09:44:25 +0000 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2020-03-03 09:44:25 +0000 |
commit | c4001c803d38564d037bade56cc8fb5a1bd4ebe0 (patch) | |
tree | 5a769f3abd932d81d43823aa4349cafee3e5302a | |
parent | 7eceaa91a57a82c822cb07a3dd02155f20d3ea09 (diff) | |
parent | 57c291bc25446e490bb2fc2b9bfd2b9939590f59 (diff) | |
download | buildstream-c4001c803d38564d037bade56cc8fb5a1bd4ebe0.tar.gz |
Merge branch 'juerg/buildbox-signals' into 'master'
_sandboxbuildboxrun.py: Fix signal handling
See merge request BuildStream/buildstream!1826
-rw-r--r-- | src/buildstream/sandbox/_sandboxbuildboxrun.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/buildstream/sandbox/_sandboxbuildboxrun.py b/src/buildstream/sandbox/_sandboxbuildboxrun.py index df0703dfd..b7fc7a6d5 100644 --- a/src/buildstream/sandbox/_sandboxbuildboxrun.py +++ b/src/buildstream/sandbox/_sandboxbuildboxrun.py @@ -18,6 +18,7 @@ import os import signal import subprocess import sys +from contextlib import ExitStack import psutil @@ -137,9 +138,23 @@ class SandboxBuildBoxRun(SandboxREAPI): group_id = os.getpgid(process.pid) os.killpg(group_id, signal.SIGCONT) - with _signals.suspendable(suspend_proc, resume_proc), _signals.terminator(kill_proc): + with ExitStack() as stack: + + # We want to launch buildbox-run in a new session in non-interactive + # mode so that we handle the SIGTERM and SIGTSTP signals separately + # from the nested process, but in interactive mode this causes + # launched shells to lack job control as the signals don't reach + # the shell process. + # + if interactive: + new_session = False + else: + new_session = True + stack.enter_context(_signals.suspendable(suspend_proc, resume_proc)) + stack.enter_context(_signals.terminator(kill_proc)) + process = subprocess.Popen( - argv, close_fds=True, stdin=stdin, stdout=stdout, stderr=stderr, start_new_session=interactive, + argv, close_fds=True, stdin=stdin, stdout=stdout, stderr=stderr, start_new_session=new_session, ) # Wait for the child process to finish, ensuring that |