1 |
On 11/18/18 12:53 AM, Michał Górny wrote: |
2 |
> Signed-off-by: Michał Górny <mgorny@g.o> |
3 |
> --- |
4 |
> bin/pid-ns-init | 25 +++++++++++++++++++++++++ |
5 |
> lib/portage/process.py | 11 ++++++----- |
6 |
> 2 files changed, 31 insertions(+), 5 deletions(-) |
7 |
> create mode 100644 bin/pid-ns-init |
8 |
> |
9 |
> diff --git a/bin/pid-ns-init b/bin/pid-ns-init |
10 |
> new file mode 100644 |
11 |
> index 000000000..90660571a |
12 |
> --- /dev/null |
13 |
> +++ b/bin/pid-ns-init |
14 |
> @@ -0,0 +1,25 @@ |
15 |
> +#!/usr/bin/env python |
16 |
> +# Copyright 2018 Gentoo Authors |
17 |
> +# Distributed under the terms of the GNU General Public License v2 |
18 |
> + |
19 |
> +import os |
20 |
> +import sys |
21 |
> + |
22 |
> + |
23 |
> +def main(argv): |
24 |
> + if len(argv) < 2: |
25 |
> + return 'Usage: {} <main-child-pid>'.format(argv[0]) |
26 |
> + main_child_pid = int(argv[1]) |
27 |
> + |
28 |
> + # wait for child processes |
29 |
> + while True: |
30 |
> + pid, status = os.wait() |
31 |
> + if pid == main_child_pid: |
32 |
> + return os.WEXITSTATUS(status) |
33 |
|
34 |
Technically, is not valid to call WEXITSTATUS unless WIFEXITED called |
35 |
true. If the child process was killed by a signal, we have a couple of |
36 |
options: |
37 |
|
38 |
1) Kill the current process with the same signal, as suggested in |
39 |
https://www.cons.org/cracauer/sigint.html. |
40 |
|
41 |
2) Fake it by exiting with 128 + signum (this is what dumb-init does). |
42 |
|
43 |
-- |
44 |
Thanks, |
45 |
Zac |