[Cmake-commits] [cmake-commits] king committed ProcessUNIX.c 1.89 1.90

cmake-commits at cmake.org cmake-commits at cmake.org
Mon Nov 30 13:14:04 EST 2009


Update of /cvsroot/CMake/CMake/Source/kwsys
In directory public:/mounts/ram/cvs-serv32022/Source/kwsys

Modified Files:
	ProcessUNIX.c 
Log Message:
KWSys: Restore SIGSTOP/SIGKILL to end process tree

On UNIX systems we kill a tree of processes by performing a DFS walk of
the tree.  We send SIGSTOP to each process encountered, recursively
handle its children, and then send SIGKILL.

We once used the above approach in the past, but it was removed by the
commit "Do not send both SIGSTOP and SIGKILL when killing a process".
The commit was meant to work-around an OS X 10.3 bug in which the child
would not always honor SIGKILL after SIGSTOP.  At the time we wrongly
assumed that the process tree remains intact after SIGKILL and before
the child is reaped.  In fact the grandchildren may be re-parented to
ppid=1 even before the child is reaped, which causes the DFS walk to
miss them.


Index: ProcessUNIX.c
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/kwsys/ProcessUNIX.c,v
retrieving revision 1.89
retrieving revision 1.90
diff -C 2 -d -r1.89 -r1.90
*** ProcessUNIX.c	19 Oct 2009 16:57:36 -0000	1.89
--- ProcessUNIX.c	30 Nov 2009 18:14:02 -0000	1.90
***************
*** 2393,2403 ****
  #endif
  
!   /* Kill the process now to make sure it does not create more
!      children.  Do not reap it yet so we can identify its existing
!      children.  There is a small race condition here.  If the child
!      forks after we begin looking for children below but before it
!      receives this kill signal we might miss a child.  Also we might
!      not be able to catch up to a fork bomb.  */
!   kill(process_id, SIGKILL);
  
    /* Kill all children if we can find them.  */
--- 2393,2398 ----
  #endif
  
!   /* Suspend the process to be sure it will not create more children.  */
!   kill(process_id, SIGSTOP);
  
    /* Kill all children if we can find them.  */
***************
*** 2487,2490 ****
--- 2482,2498 ----
  #endif
      }
+ 
+   /* Kill the process.  */
+   kill(process_id, SIGKILL);
+ 
+ #if defined(__APPLE__)
+   /* On OS X 10.3 the above SIGSTOP occasionally prevents the SIGKILL
+      from working.  Just in case, we resume the child and kill it
+      again.  There is a small race condition in this obscure case.  If
+      the child manages to fork again between these two signals, we
+      will not catch its children.  */
+   kill(process_id, SIGCONT);
+   kill(process_id, SIGKILL);
+ #endif
  }
  



More information about the Cmake-commits mailing list