Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH] pid-sandbox: pid-ns-init TIOCSCTTY after setsid (bug 675868)
Date: Sun, 27 Jan 2019 20:28:02
Message-Id: 20190127202713.29807-1-zmedico@gentoo.org
1 Set the controlling terminal to the stdout pty after calling setsid,
2 in order to avoid "No such device or address" ENXIO errors when
3 attempting to open /dev/tty.
4
5 Bug: https://bugs.gentoo.org/675868
6 Signed-off-by: Zac Medico <zmedico@g.o>
7 ---
8 bin/pid-ns-init | 11 +++++++++++
9 1 file changed, 11 insertions(+)
10
11 diff --git a/bin/pid-ns-init b/bin/pid-ns-init
12 index f01d69fc2..ac4509bd0 100644
13 --- a/bin/pid-ns-init
14 +++ b/bin/pid-ns-init
15 @@ -3,12 +3,14 @@
16 # Distributed under the terms of the GNU General Public License v2
17
18 import errno
19 +import fcntl
20 import functools
21 import os
22 import platform
23 import signal
24 import subprocess
25 import sys
26 +import termios
27
28
29 KILL_SIGNALS = (
30 @@ -75,6 +77,15 @@ def main(argv):
31 # Isolate parent process from process group SIGSTOP (bug 675870)
32 setsid = True
33 os.setsid()
34 + try:
35 + fcntl.ioctl(sys.stdout, termios.TIOCSCTTY, 0)
36 + except OSError as e:
37 + if e.errno == errno.EPERM:
38 + # This means that stdout refers to the same tty as the parent
39 + # process, and in this case we do not want to steel it.
40 + pass
41 + else:
42 + raise
43 proc = subprocess.Popen(args, executable=binary, **popen_kwargs)
44 main_child_pid = proc.pid
45
46 --
47 2.18.1