From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [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 DA30D138359 for ; Sun, 1 Nov 2020 21:46:18 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 31A43E0871; Sun, 1 Nov 2020 21:46:18 +0000 (UTC) Received: from smtp.gentoo.org (smtp.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 1AA59E0871 for ; Sun, 1 Nov 2020 21:46:18 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 33B8F335C6F for ; Sun, 1 Nov 2020 21:46:17 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id B2B39395 for ; Sun, 1 Nov 2020 21:46:15 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1604267101.8b7edb648814cc53774c5841e45d8cc325bcef6e.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/pid-ns-init X-VCS-Directories: bin/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 8b7edb648814cc53774c5841e45d8cc325bcef6e X-VCS-Branch: master Date: Sun, 1 Nov 2020 21:46:15 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: bd96998c-6a6f-402c-832a-3472b62062ad X-Archives-Hash: 554820cf0d48ec0213f4cce7503d2d3a commit: 8b7edb648814cc53774c5841e45d8cc325bcef6e Author: Zac Medico gentoo org> AuthorDate: Wed Oct 28 08:34:51 2020 +0000 Commit: Zac Medico gentoo org> CommitDate: Sun Nov 1 21:45:01 2020 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=8b7edb64 pid-sandbox: Forward SIGTSTP and SIGCONT (bug 704498) For correct operation of Ctrl+Z, forward SIGTSTP and SIGCONT to all sandboxed pids. Fixes: 37e4dc5ae842 ("pid-sandbox: pid-ns-init setsid support (bug 675870)") Bug: https://bugs.gentoo.org/704498 Signed-off-by: Zac Medico gentoo.org> bin/pid-ns-init | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/bin/pid-ns-init b/bin/pid-ns-init index 3a218a5df..e410dd028 100644 --- a/bin/pid-ns-init +++ b/bin/pid-ns-init @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright 2018-2019 Gentoo Authors +# Copyright 2018-2020 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 import errno @@ -19,6 +19,11 @@ KILL_SIGNALS = ( signal.SIGHUP, ) +SIGTSTP_SIGCONT = ( + signal.SIGTSTP, + signal.SIGCONT, +) + def forward_kill_signal(pid, signum, frame): if pid == 0: @@ -28,6 +33,18 @@ def forward_kill_signal(pid, signum, frame): os.kill(pid, signum) +def forward_sigtstp_sigcont(pid, signum, frame): + handler = None + if pid == 0: + # Temporarily disable the handler in order to prevent it from + # being called recursively, since the signal will also be sent + # to the current process. + handler = signal.signal(signum, signal.SIG_DFL) + os.kill(pid, signum) + if handler is not None: + signal.signal(signum, handler) + + def preexec_fn(uid, gid, groups, umask): if gid is not None: os.setgid(gid) @@ -97,6 +114,11 @@ def main(argv): for signum in KILL_SIGNALS: signal.signal(signum, sig_handler) + # For correct operation of Ctrl+Z, forward SIGTSTP and SIGCONT. + sigtstp_sigcont_handler = functools.partial(forward_sigtstp_sigcont, 0 if setsid else main_child_pid) + for signum in SIGTSTP_SIGCONT: + signal.signal(signum, sigtstp_sigcont_handler) + # wait for child processes while True: try: