ebuils-ipc.py: _exit in finally block after fork
authorZac Medico <zmedico@gentoo.org>
Wed, 14 Dec 2011 04:06:10 +0000 (20:06 -0800)
committerZac Medico <zmedico@gentoo.org>
Wed, 14 Dec 2011 04:06:10 +0000 (20:06 -0800)
bin/ebuild-ipc.py

index 68ad985b6b8f0fb1a0888bec01b284debbd76bbb..372585f7ba9ad8de1c245638e1f063a56653d737 100755 (executable)
@@ -13,6 +13,7 @@ import select
 import signal
 import sys
 import time
+import traceback
 
 def debug_signal(signum, frame):
        import pdb
@@ -228,14 +229,22 @@ class EbuildIpc(object):
                pid = os.fork()
 
                if pid == 0:
-                       os.close(pr)
-
-                       # File streams are in unbuffered mode since we do atomic
-                       # read and write of whole pickles.
-                       output_file = open(self.ipc_in_fifo, 'wb', 0)
-                       output_file.write(pickle.dumps(args))
-                       output_file.close()
-                       os._exit(os.EX_OK)
+                       retval = 1
+                       try:
+                               os.close(pr)
+
+                               # File streams are in unbuffered mode since we do atomic
+                               # read and write of whole pickles.
+                               output_file = open(self.ipc_in_fifo, 'wb', 0)
+                               output_file.write(pickle.dumps(args))
+                               output_file.close()
+                               retval = os.EX_OK
+                       except SystemExit:
+                               raise
+                       except:
+                               traceback.print_exc()
+                       finally:
+                               os._exit(retval)
 
                os.close(pw)
 
@@ -258,9 +267,16 @@ class EbuildIpc(object):
                pid = os.fork()
 
                if pid == 0:
-                       os.close(pr)
-                       retval = self._receive_reply(input_fd)
-                       os._exit(retval)
+                       retval = 1
+                       try:
+                               os.close(pr)
+                               retval = self._receive_reply(input_fd)
+                       except SystemExit:
+                               raise
+                       except:
+                               traceback.print_exc()
+                       finally:
+                               os._exit(retval)
 
                os.close(pw)
                retval = self._wait(pid, pr, portage.localization._('during read'))