* [gentoo-portage-dev] [PATCH] pid-sandbox: pid-ns-init TIOCSCTTY after setsid (bug 675868)
@ 2019-01-27 20:27 Zac Medico
0 siblings, 0 replies; only message in thread
From: Zac Medico @ 2019-01-27 20:27 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Zac Medico
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>
---
bin/pid-ns-init | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/bin/pid-ns-init b/bin/pid-ns-init
index f01d69fc2..ac4509bd0 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,15 @@ def main(argv):
# Isolate parent process from process group SIGSTOP (bug 675870)
setsid = True
os.setsid()
+ try:
+ fcntl.ioctl(sys.stdout, termios.TIOCSCTTY, 0)
+ except OSError as e:
+ if e.errno == errno.EPERM:
+ # This means that stdout refers to the same tty as 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
--
2.18.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2019-01-27 20:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-27 20:27 [gentoo-portage-dev] [PATCH] pid-sandbox: pid-ns-init TIOCSCTTY after setsid (bug 675868) Zac Medico
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox