From c85a7c249b3cd3f7ffea5c14acce868b4cb7bae4 Mon Sep 17 00:00:00 2001
From: Brad King <brad.king@kitware.com>
Date: Sat, 31 Dec 2005 12:59:31 -0500
Subject: [PATCH] BUG: When more than one command is given and one of them
 fails to start and the rest are killed, do not forget to reap the killed
 children.

---
 ProcessUNIX.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/ProcessUNIX.c b/ProcessUNIX.c
index 42524687..488e6bc6 100644
--- a/ProcessUNIX.c
+++ b/ProcessUNIX.c
@@ -1187,11 +1187,17 @@ static void kwsysProcessCleanup(kwsysProcess* cp, int error)
     /* Kill any children already started.  */
     if(cp->ForkPIDs)
       {
+      int status;
       for(i=0; i < cp->NumberOfCommands; ++i)
         {
         if(cp->ForkPIDs[i])
           {
+          /* Kill the child.  */
           kwsysProcessKill(cp->ForkPIDs[i]);
+          /* Reap the child.  Keep trying until the call is not
+             interrupted.  */
+          while((waitpid(cp->ForkPIDs[i], &status, 0) < 0) &&
+                (errno == EINTR));
           }
         }
       }
-- 
GitLab