Commented on the bug due to reasoning behind this patch. Essentially, SIGTERM 
is sent to "tee", a WNOHANG waitpid() is performed followed by SIGKILL if it 
hasn't exited. So if tee doesn't exit immediately upon getting the SIGTERM, 
its buffers won't get a chance to get to disk due to it being killed. This 
patch simply adds a 1 second window between the SIGTERM and the SIGKILL.

One question; is the waitpid(x,0) necessary in the case where SIGKILL wasn't 
sent? Is waitpid(x,os.NOHANG) enough to clean up the zombie when SIGTERM 
succeeds? If so, the waitpid(x,0) could be indented into the "if not 
timeout:" block.

--
Jason Stubbs
Index: pym/portage_exec.py
===================================================================
--- pym/portage_exec.py	(revision 2150)
+++ pym/portage_exec.py	(working copy)
@@ -4,7 +4,7 @@
 # $Id: /var/cvsroot/gentoo-src/portage/pym/portage_exec.py,v 1.13.2.4 2005/04/17 09:01:56 jstubbs Exp $
 
 
-import os,types,atexit,string,stat
+import os,types,atexit,string,stat,time
 import signal
 import portage_data
 import portage_util
@@ -182,7 +182,13 @@
 			for x in mypid[0:-1]:
 				try:
 					os.kill(x,signal.SIGTERM)
-					if os.waitpid(x,os.WNOHANG)[1] == 0:
+					timeout = 100
+					while timeout:
+						if os.waitpid(x,os.WNOHANG)[1] != 0:
+							break
+						time.sleep(0.01)
+						timeout -= 1
+					if not timeout:
 						# feisty bugger, still alive.
 						os.kill(x,signal.SIGKILL)
 					os.waitpid(x,0)

Reply via email to