From: Zac Medico <zmedico@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org
Cc: Zac Medico <zmedico@gentoo.org>
Subject: [gentoo-portage-dev] [PATCH] pid-sandbox: Forward SIGTSTP and SIGCONT (bug 704498)
Date: Wed, 28 Oct 2020 15:54:08 -0700 [thread overview]
Message-ID: <20201028225408.181647-1-zmedico@gentoo.org> (raw)
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 <zmedico@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:
--
2.26.2
reply other threads:[~2020-10-28 22:54 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201028225408.181647-1-zmedico@gentoo.org \
--to=zmedico@gentoo.org \
--cc=gentoo-portage-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox