summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2019-01-27 12:24:55 -0800
committerZac Medico <zmedico@gentoo.org>2019-01-27 12:45:53 -0800
commitce0656337268601aeadff091ea4f683eeea16148 (patch)
treea8e68299c24755ea383e1e4ce29afd1339d6a0c5
parentUpdates for portage-2.3.58 release (diff)
downloadportage-ce0656337268601aeadff091ea4f683eeea16148.tar.gz
portage-ce0656337268601aeadff091ea4f683eeea16148.tar.bz2
portage-ce0656337268601aeadff091ea4f683eeea16148.zip
pid-sandbox: pid-ns-init TIOCSCTTY after setsid (bug 675868)
Set the controlling terminal to the stdout pty after calling setsid, in order to avoid "No such device or address" ENXIO errors when attempting to open /dev/tty. Bug: https://bugs.gentoo.org/675868 Signed-off-by: Zac Medico <zmedico@gentoo.org>
-rw-r--r--bin/pid-ns-init13
1 files changed, 13 insertions, 0 deletions
diff --git a/bin/pid-ns-init b/bin/pid-ns-init
index f01d69fc2..d8e67cf6d 100644
--- a/bin/pid-ns-init
+++ b/bin/pid-ns-init
@@ -3,12 +3,14 @@
# Distributed under the terms of the GNU General Public License v2
import errno
+import fcntl
import functools
import os
import platform
import signal
import subprocess
import sys
+import termios
KILL_SIGNALS = (
@@ -75,6 +77,17 @@ def main(argv):
# Isolate parent process from process group SIGSTOP (bug 675870)
setsid = True
os.setsid()
+ if sys.stdout.isatty():
+ try:
+ fcntl.ioctl(sys.stdout, termios.TIOCSCTTY, 0)
+ except OSError as e:
+ if e.errno == errno.EPERM:
+ # This means that stdout refers to the controlling terminal
+ # of the parent process, and in this case we do not want to
+ # steel it.
+ pass
+ else:
+ raise
proc = subprocess.Popen(args, executable=binary, **popen_kwargs)
main_child_pid = proc.pid