1 |
commit: 8b7edb648814cc53774c5841e45d8cc325bcef6e |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Oct 28 08:34:51 2020 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Nov 1 21:45:01 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=8b7edb64 |
7 |
|
8 |
pid-sandbox: Forward SIGTSTP and SIGCONT (bug 704498) |
9 |
|
10 |
For correct operation of Ctrl+Z, forward SIGTSTP and SIGCONT |
11 |
to all sandboxed pids. |
12 |
|
13 |
Fixes: 37e4dc5ae842 ("pid-sandbox: pid-ns-init setsid support (bug 675870)") |
14 |
Bug: https://bugs.gentoo.org/704498 |
15 |
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> |
16 |
|
17 |
bin/pid-ns-init | 24 +++++++++++++++++++++++- |
18 |
1 file changed, 23 insertions(+), 1 deletion(-) |
19 |
|
20 |
diff --git a/bin/pid-ns-init b/bin/pid-ns-init |
21 |
index 3a218a5df..e410dd028 100644 |
22 |
--- a/bin/pid-ns-init |
23 |
+++ b/bin/pid-ns-init |
24 |
@@ -1,5 +1,5 @@ |
25 |
#!/usr/bin/env python |
26 |
-# Copyright 2018-2019 Gentoo Authors |
27 |
+# Copyright 2018-2020 Gentoo Authors |
28 |
# Distributed under the terms of the GNU General Public License v2 |
29 |
|
30 |
import errno |
31 |
@@ -19,6 +19,11 @@ KILL_SIGNALS = ( |
32 |
signal.SIGHUP, |
33 |
) |
34 |
|
35 |
+SIGTSTP_SIGCONT = ( |
36 |
+ signal.SIGTSTP, |
37 |
+ signal.SIGCONT, |
38 |
+) |
39 |
+ |
40 |
|
41 |
def forward_kill_signal(pid, signum, frame): |
42 |
if pid == 0: |
43 |
@@ -28,6 +33,18 @@ def forward_kill_signal(pid, signum, frame): |
44 |
os.kill(pid, signum) |
45 |
|
46 |
|
47 |
+def forward_sigtstp_sigcont(pid, signum, frame): |
48 |
+ handler = None |
49 |
+ if pid == 0: |
50 |
+ # Temporarily disable the handler in order to prevent it from |
51 |
+ # being called recursively, since the signal will also be sent |
52 |
+ # to the current process. |
53 |
+ handler = signal.signal(signum, signal.SIG_DFL) |
54 |
+ os.kill(pid, signum) |
55 |
+ if handler is not None: |
56 |
+ signal.signal(signum, handler) |
57 |
+ |
58 |
+ |
59 |
def preexec_fn(uid, gid, groups, umask): |
60 |
if gid is not None: |
61 |
os.setgid(gid) |
62 |
@@ -97,6 +114,11 @@ def main(argv): |
63 |
for signum in KILL_SIGNALS: |
64 |
signal.signal(signum, sig_handler) |
65 |
|
66 |
+ # For correct operation of Ctrl+Z, forward SIGTSTP and SIGCONT. |
67 |
+ sigtstp_sigcont_handler = functools.partial(forward_sigtstp_sigcont, 0 if setsid else main_child_pid) |
68 |
+ for signum in SIGTSTP_SIGCONT: |
69 |
+ signal.signal(signum, sigtstp_sigcont_handler) |
70 |
+ |
71 |
# wait for child processes |
72 |
while True: |
73 |
try: |