You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by ak...@apache.org on 2022/11/05 11:19:42 UTC

[buildstream] 01/01: _sandboxbuildboxrun.py: Restore terminal after exit of interactive child

This is an automated email from the ASF dual-hosted git repository.

akitouni pushed a commit to branch abderrahim/background
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 7393276c5c024aec942541b463723bca19004b95
Author: Abderrahim Kitouni <ak...@gnome.org>
AuthorDate: Sat Nov 5 12:18:46 2022 +0100

    _sandboxbuildboxrun.py: Restore terminal after exit of interactive child
    
    This is a port of 8f401127c450ea1c2a1e2878d2ac28a7166d355c to the
    buildbox-run sandbox
    
    Fixes #1690
---
 src/buildstream/sandbox/_sandboxbuildboxrun.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/buildstream/sandbox/_sandboxbuildboxrun.py b/src/buildstream/sandbox/_sandboxbuildboxrun.py
index 1987ebac1..3a82e4d11 100644
--- a/src/buildstream/sandbox/_sandboxbuildboxrun.py
+++ b/src/buildstream/sandbox/_sandboxbuildboxrun.py
@@ -223,6 +223,18 @@ class SandboxBuildBoxRun(SandboxREAPI):
             except psutil.NoSuchProcess:
                 pass
 
+            if interactive:
+                # Make this process the foreground process again, otherwise the
+                # next read() on stdin will trigger SIGTTIN and stop the process.
+                # This is required because the sandboxed process does not have
+                # permission to do this on its own (running in separate PID namespace).
+                #
+                # tcsetpgrp() will trigger SIGTTOU when called from a background
+                # process, so ignore it temporarily.
+                handler = signal.signal(signal.SIGTTOU, signal.SIG_IGN)
+                os.tcsetpgrp(0, os.getpid())
+                signal.signal(signal.SIGTTOU, handler)
+
             if returncode != 0:
                 raise SandboxError("buildbox-run failed with returncode {}".format(returncode))