From a457a6c7c8fa17e0cec137c68a6a090edeb23e57 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Tue, 11 Jun 2024 17:44:25 +0200 Subject: 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. --- examples/unschroot.py | 2 ++ 1 file changed, 2 insertions(+) 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) -- cgit v1.2.3