diff options
author | Jürg Billeter <j@bitron.ch> | 2020-03-02 18:00:46 +0100 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2020-03-02 18:42:58 +0100 |
commit | 57c291bc25446e490bb2fc2b9bfd2b9939590f59 (patch) | |
tree | 5a769f3abd932d81d43823aa4349cafee3e5302a /src | |
parent | 7eceaa91a57a82c822cb07a3dd02155f20d3ea09 (diff) | |
download | buildstream-57c291bc25446e490bb2fc2b9bfd2b9939590f59.tar.gz |
_sandboxbuildboxrun.py: Fix signal handlingjuerg/buildbox-signals
This fixes resume in non-interactive mode and job control in interactive
shells, matching the behavior of `SandboxBwrap`.
Diffstat (limited to 'src')
-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 |