test_ipc_daemon: handle fork/finally race
authorZac Medico <zmedico@gentoo.org>
Mon, 8 Oct 2012 15:08:51 +0000 (08:08 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 8 Oct 2012 15:08:51 +0000 (08:08 -0700)
pym/portage/tests/ebuild/test_ipc_daemon.py

index a871076259433fb61fe140d112d649d3158d5611..b88fce6955f36e368c441cbd9a7e42d43e366113 100644 (file)
@@ -36,6 +36,7 @@ class IpcDaemonTestCase(TestCase):
        def testIpcDaemon(self):
                event_loop = global_event_loop()
                tmpdir = tempfile.mkdtemp()
+               main_pid = os.getpid()
                build_dir = None
                try:
                        env = {}
@@ -135,6 +136,14 @@ class IpcDaemonTestCase(TestCase):
                                self.assertEqual(proc.returncode == os.EX_OK, False)
 
                finally:
+
+                       # Ensure that finally blocks don't run in forked subprocesses
+                       # before they are able to exec or _exit themselves, since the
+                       # fork might fail or be killed before it can setup its own
+                       # try/finally/_exit routine. See bug #345289.
+                       if os.getpid() != main_pid:
+                               os._exit(1)
+
                        if build_dir is not None:
                                build_dir.unlock()
                        shutil.rmtree(tmpdir)