From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (unknown [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 21851138334 for ; Sun, 27 Jan 2019 20:28:02 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0BBFDE10FB; Sun, 27 Jan 2019 20:27:56 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id D7511E10FB for ; Sun, 27 Jan 2019 20:27:55 +0000 (UTC) Received: from localhost.localdomain (unknown [IPv6:2600:8802:604:6600:b06e:5315:d0a7:5889]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: zmedico) by smtp.gentoo.org (Postfix) with ESMTPSA id EBFC0335D60; Sun, 27 Jan 2019 20:27:53 +0000 (UTC) From: Zac Medico To: gentoo-portage-dev@lists.gentoo.org Cc: Zac Medico Subject: [gentoo-portage-dev] [PATCH] pid-sandbox: pid-ns-init TIOCSCTTY after setsid (bug 675868) Date: Sun, 27 Jan 2019 12:27:13 -0800 Message-Id: <20190127202713.29807-1-zmedico@gentoo.org> X-Mailer: git-send-email 2.18.1 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: f53e233b-706a-405a-9e38-2fde7ac80334 X-Archives-Hash: c65c74ad30f8c1ef106b4ab9273c1280 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 --- 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