From b12d8dcd56e546e87b23e7481deef90bbdb0df03 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Thu, 12 Jun 2025 10:56:35 +0200 Subject: 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. --- linuxnamespaces/__init__.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'linuxnamespaces/__init__.py') 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) -- cgit v1.2.3