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