summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2025-08-18 21:23:18 +0200
committerHelmut Grohne <helmut@subdivi.de>2025-08-18 21:23:18 +0200
commit6f43d14c91da544b26f1f901e7105e11c08f7d9c (patch)
tree591e58009d003cf28a74ec607fbb90690d6423d6
parent964d52e62e64de4b860770743f08815acc99d9d3 (diff)
downloadpython-linuxnamespaces-6f43d14c91da544b26f1f901e7105e11c08f7d9c.tar.gz
examples/unschroot_*.py: improve error message for exec failure
Suggested-by: Jérémy Lal <kapouer@melix.org>
-rwxr-xr-xexamples/unschroot_fs.py8
-rwxr-xr-xexamples/unschroot_proc.py6
2 files changed, 12 insertions, 2 deletions
diff --git a/examples/unschroot_fs.py b/examples/unschroot_fs.py
index d5f67b0..fbc9bfc 100755
--- a/examples/unschroot_fs.py
+++ b/examples/unschroot_fs.py
@@ -421,7 +421,13 @@ def do_run_session(args: argparse.Namespace) -> None:
args.command.append("bash")
# Wait until Python has handed off to Perl.
os.read(rfd, 1)
- os.execvp(args.command[0], args.command)
+ try:
+ os.execvp(args.command[0], args.command)
+ except OSError as err:
+ print(
+ f"failed to exec {args.command[0]}: {err}", file=sys.stderr
+ )
+ os._exit(127)
else:
rfd.close()
linuxnamespaces.prctl_set_pdeathsig(signal.SIGKILL)
diff --git a/examples/unschroot_proc.py b/examples/unschroot_proc.py
index 96da4e5..e75b80b 100755
--- a/examples/unschroot_proc.py
+++ b/examples/unschroot_proc.py
@@ -718,7 +718,11 @@ class ContainerSupervisor(asyncvarlink.VarlinkInterface):
# The container may change this, but it's still useful for
# robustness when it does not.
linuxnamespaces.prctl_set_pdeathsig(signal.SIGKILL)
- os.execvp(command[0], command)
+ try:
+ os.execvp(command[0], command)
+ except OSError as err:
+ print(f"failed to exec {command[0]}: {err}", file=sys.stderr)
+ os._exit(127)
# The caller should call Terminate next. Doing so will close the wpipe
# and thus allow the child process to proceed.