diff options
author | Helmut Grohne <helmut@subdivi.de> | 2025-06-12 10:56:35 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2025-06-12 10:56:35 +0200 |
commit | b12d8dcd56e546e87b23e7481deef90bbdb0df03 (patch) | |
tree | b37c0d1b7a994bb04871408ea3c2f0b1f9adff9b | |
parent | b260a3d682256b5b7eee47ad7b33b16acfd57b5e (diff) | |
download | python-linuxnamespaces-b12d8dcd56e546e87b23e7481deef90bbdb0df03.tar.gz |
run_in_fork should never propagate exceptions from the child
Otherwise an exception handler in the caller may be invoked in
unexpected ways. If an exception occurs, exit non-zero and reraise in
the parent with less detail.
-rw-r--r-- | linuxnamespaces/__init__.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/linuxnamespaces/__init__.py b/linuxnamespaces/__init__.py index a39f43a..8adf45b 100644 --- a/linuxnamespaces/__init__.py +++ b/linuxnamespaces/__init__.py @@ -33,9 +33,12 @@ class run_in_fork: self.efd = EventFD() self.pid = os.fork() if self.pid == 0: - self.efd.read() - self.efd.close() - function() + try: + self.efd.read() + self.efd.close() + function() + except: + os._exit(1) os._exit(0) def start(self) -> None: @@ -80,9 +83,12 @@ class async_run_in_fork: self.efd = EventFD() self.pid = os.fork() if self.pid == 0: - self.efd.read() - self.efd.close() - function() + try: + self.efd.read() + self.efd.close() + function() + except: + os._exit(1) os._exit(0) watcher.add_child_handler(self.pid, self._child_callback) |