1 |
On 18/11/18 09:18, Michał Górny wrote: |
2 |
> On Sun, 2018-11-18 at 09:04 +0000, M. J. Everitt wrote: |
3 |
>> On 18/11/18 08:53, Michał Górny wrote: |
4 |
>>> Signed-off-by: Michał Górny <mgorny@g.o> |
5 |
>>> --- |
6 |
>>> bin/pid-ns-init | 25 +++++++++++++++++++++++++ |
7 |
>>> lib/portage/process.py | 11 ++++++----- |
8 |
>>> 2 files changed, 31 insertions(+), 5 deletions(-) |
9 |
>>> create mode 100644 bin/pid-ns-init |
10 |
>>> |
11 |
>>> diff --git a/bin/pid-ns-init b/bin/pid-ns-init |
12 |
>>> new file mode 100644 |
13 |
>>> index 000000000..90660571a |
14 |
>>> --- /dev/null |
15 |
>>> +++ b/bin/pid-ns-init |
16 |
>>> @@ -0,0 +1,25 @@ |
17 |
>>> +#!/usr/bin/env python |
18 |
>>> +# Copyright 2018 Gentoo Authors |
19 |
>>> +# Distributed under the terms of the GNU General Public License v2 |
20 |
>>> + |
21 |
>>> +import os |
22 |
>>> +import sys |
23 |
>>> + |
24 |
>>> + |
25 |
>>> +def main(argv): |
26 |
>>> + if len(argv) < 2: |
27 |
>>> + return 'Usage: {} <main-child-pid>'.format(argv[0]) |
28 |
>>> + main_child_pid = int(argv[1]) |
29 |
>>> + |
30 |
>>> + # wait for child processes |
31 |
>>> + while True: |
32 |
>>> + pid, status = os.wait() |
33 |
>>> + if pid == main_child_pid: |
34 |
>>> + return os.WEXITSTATUS(status) |
35 |
>>> + |
36 |
>>> + # this should never be reached |
37 |
>>> + return 127 |
38 |
>>> + |
39 |
>>> + |
40 |
>>> +if __name__ == '__main__': |
41 |
>>> + sys.exit(main(sys.argv)) |
42 |
>>> diff --git a/lib/portage/process.py b/lib/portage/process.py |
43 |
>>> index dee126c3c..75ec299f0 100644 |
44 |
>>> --- a/lib/portage/process.py |
45 |
>>> +++ b/lib/portage/process.py |
46 |
>>> @@ -544,13 +544,14 @@ def _exec(binary, mycommand, opt_name, fd_pipes, env, gid, groups, uid, umask, |
47 |
>>> else: |
48 |
>>> if unshare_pid: |
49 |
>>> # pid namespace requires us to become init |
50 |
>>> - # TODO: do init-ty stuff |
51 |
>>> - # therefore, fork() ASAP |
52 |
>>> fork_ret = os.fork() |
53 |
>>> if fork_ret != 0: |
54 |
>>> - pid, status = os.waitpid(fork_ret, 0) |
55 |
>>> - assert pid == fork_ret |
56 |
>>> - os._exit(status) |
57 |
>>> + os.execv(portage._python_interpreter, [ |
58 |
>>> + portage._python_interpreter, |
59 |
>>> + os.path.join(portage._bin_path, |
60 |
>>> + 'pid-ns-init'), |
61 |
>>> + '%s' % fork_ret, |
62 |
>>> + ]) |
63 |
>>> if unshare_mount: |
64 |
>>> # mark the whole filesystem as slave to avoid |
65 |
>>> # mounts escaping the namespace |
66 |
>> Why in python?! Surely a small C app would be significantly more efficient .. |
67 |
>> |
68 |
> Surely adding a new build system for C apps would be entirely justified |
69 |
> by the necessity of premature optimization of program that spends ~100% |
70 |
> of its time in wait(). |
71 |
> |
72 |
Forgive my ignorance then .. what purpose does a process have which simply |
73 |
wait()s ?! .. no, on second thoughts, don't answer that question, I'm |
74 |
unlikely to like the answer anyway ... |