ForkProcess: increase scope of try/finally/_exit
authorZac Medico <zmedico@gentoo.org>
Mon, 8 Oct 2012 13:48:55 +0000 (06:48 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 8 Oct 2012 13:48:55 +0000 (06:48 -0700)
This minimizes the probability of triggering irrelevant finally blocks
from earlier in the call stack (bug #345289).

pym/portage/util/_async/ForkProcess.py

index 6fcd662cf9e989b4aa5d046a5eec374eade44314..96ce3d98a468b4f039af76b0752866d508ab097f 100644 (file)
@@ -25,17 +25,19 @@ class ForkProcess(SpawnProcess):
                        portage.process.spawned_pids.append(pid)
                        return [pid]
 
-               portage.locks._close_fds()
-               # Disable close_fds since we don't exec (see _setup_pipes docstring).
-               portage.process._setup_pipes(fd_pipes, close_fds=False)
-
-               # Use default signal handlers in order to avoid problems
-               # killing subprocesses as reported in bug #353239.
-               signal.signal(signal.SIGINT, signal.SIG_DFL)
-               signal.signal(signal.SIGTERM, signal.SIG_DFL)
-
                rval = 1
                try:
+
+                       # Use default signal handlers in order to avoid problems
+                       # killing subprocesses as reported in bug #353239.
+                       signal.signal(signal.SIGINT, signal.SIG_DFL)
+                       signal.signal(signal.SIGTERM, signal.SIG_DFL)
+
+                       portage.locks._close_fds()
+                       # We don't exec, so use close_fds=False
+                       # (see _setup_pipes docstring).
+                       portage.process._setup_pipes(fd_pipes, close_fds=False)
+
                        rval = self._run()
                except SystemExit:
                        raise