aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2018-11-13 22:34:14 +0100
committerMichał Górny <mgorny@gentoo.org>2018-11-18 13:25:04 +0100
commita75d5546e3a49599280c222a75471981bf2a7837 (patch)
treeec6c1082765e066e0b8ff9c7c114f0c4df630302 /bin/pid-ns-init
parentSupport FEATURES=pid-sandbox (diff)
downloadportage-a75d5546e3a49599280c222a75471981bf2a7837.tar.gz
portage-a75d5546e3a49599280c222a75471981bf2a7837.tar.bz2
portage-a75d5546e3a49599280c222a75471981bf2a7837.zip
Introduce a tiny init replacement for inside pid namespace
Reviewed-by: Zac Medico <zmedico@gentoo.org> Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'bin/pid-ns-init')
-rw-r--r--bin/pid-ns-init30
1 files changed, 30 insertions, 0 deletions
diff --git a/bin/pid-ns-init b/bin/pid-ns-init
new file mode 100644
index 000000000..843257b70
--- /dev/null
+++ b/bin/pid-ns-init
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+# Copyright 2018 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+import os
+import sys
+
+
+def main(argv):
+ if len(argv) < 2:
+ return 'Usage: {} <main-child-pid>'.format(argv[0])
+ main_child_pid = int(argv[1])
+
+ # wait for child processes
+ while True:
+ pid, status = os.wait()
+ if pid == main_child_pid:
+ if os.WIFEXITED(status):
+ return os.WEXITSTATUS(status)
+ elif os.WIFSIGNALED(status):
+ os.kill(os.getpid(), os.WTERMSIG(status))
+ # go to the unreachable place
+ break
+
+ # this should never be reached
+ return 127
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))