summaryrefslogtreecommitdiff
path: root/examples/unschroot.py
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2024-06-11 17:44:25 +0200
committerHelmut Grohne <helmut@subdivi.de>2024-06-11 18:09:04 +0200
commita457a6c7c8fa17e0cec137c68a6a090edeb23e57 (patch)
tree25d09219e03643812a9cb4f98f0dcd9dcd61bb9d /examples/unschroot.py
parente404a83f9225639636e1f955d0caf7df4df75cfe (diff)
downloadpython-linuxnamespaces-a457a6c7c8fa17e0cec137c68a6a090edeb23e57.tar.gz
unschroot: synchronize reparenting
Before this change, it could happen that we'd call prctl_set_child_subreaper before our parent actually died. Thus we'd quickly get the death signal. The additional synchronization point ensures that our previous parent process has been waited for (and thus we are reparented) before installing the death signal.
Diffstat (limited to 'examples/unschroot.py')
-rwxr-xr-xexamples/unschroot.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/examples/unschroot.py b/examples/unschroot.py
index 88c105f..3e3cc3a 100755
--- a/examples/unschroot.py
+++ b/examples/unschroot.py
@@ -228,6 +228,7 @@ def do_run_session(args: argparse.Namespace) -> None:
os.setuid(spw.pw_uid)
if not args.command:
args.command.append("bash")
+ childsock.recv(1)
linuxnamespaces.prctl_set_pdeathsig(signal.SIGTERM)
if "PATH" not in os.environ:
if spw.pw_uid == 0:
@@ -244,6 +245,7 @@ def do_run_session(args: argparse.Namespace) -> None:
pidfd = fds[0]
os.waitpid(pid, 0)
linuxnamespaces.prctl_set_child_subreaper(False)
+ mainsock.send(b"\0")
sys.exit(os.waitid(os.P_PIDFD, pidfd, os.WEXITED).si_status)