Gentoo Archives: gentoo-commits

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