commit:     c82dc8c8fe92979b82df4c71bb9961973367e8f9
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 29 17:38:20 2024 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Jan 29 17:43:27 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=c82dc8c8

_start_fork: Ensure any _setup_pipes exception is displayed

Fixes: 7ec7a647ef6e ("process.spawn: add abstraction layer for os.fork()")
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/portage/process.py | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/lib/portage/process.py b/lib/portage/process.py
index be1c5d350a..71750a715f 100644
--- a/lib/portage/process.py
+++ b/lib/portage/process.py
@@ -658,13 +658,8 @@ def _exec_wrapper(
             writemsg(
                 f"ERROR: Executing {mycommand} failed with E2BIG. Child 
process environment size: {env_stats.env_size} bytes. Largest environment 
variable: {env_stats.env_largest_name} ({env_stats.env_largest_size} bytes)\n"
             )
-
-        # We need to catch _any_ exception so that it doesn't
-        # propagate out of this function and cause exiting
-        # with anything other than os._exit()
         writemsg(f"{e}:\n   {' '.join(mycommand)}\n", noiselevel=-1)
-        traceback.print_exc()
-        sys.stderr.flush()
+        raise
 
 
 def _exec(
@@ -1174,8 +1169,14 @@ def _start_fork(
         pid = os.fork()
 
         if pid == 0:
-            _setup_pipes(fd_pipes, close_fds=close_fds, inheritable=True)
-            target(*args, **kwargs)
+            try:
+                _setup_pipes(fd_pipes, close_fds=close_fds, inheritable=True)
+                target(*args, **kwargs)
+            except Exception:
+                # We need to catch _any_ exception and display it since the 
child
+                # process must unconditionally exit via os._exit() if exec 
fails.
+                traceback.print_exc()
+                sys.stderr.flush()
     finally:
         # Don't used portage.getpid() here, in case there is a race
         # with getpid cache invalidation via _ForkWatcher hook.

Reply via email to