[commit: packages/process] master: Fix bug in multi-threaded waitForProcess (5b99d45)

git at git.haskell.org git at git.haskell.org
Wed Jul 19 21:19:05 UTC 2017


Repository : ssh://git@git.haskell.org/process

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/5b99d45103d1edf6f596c353f548221d897db4cf/process

>---------------------------------------------------------------

commit 5b99d45103d1edf6f596c353f548221d897db4cf
Author: Charles Cooper <cooper.charles.m at gmail.com>
Date:   Sat Apr 2 17:42:56 2016 -0400

    Fix bug in multi-threaded waitForProcess
    
    Previously an exception was being thrown when multiple threads were
    blocking on waitForProcess due to inconsistent handling of the return
    code of `waitpid`:
    
    "If more than one thread is suspended in waitpid() awaiting termination
    of the same process, exactly one thread returns the process status at
    the time of the target child process termination. The other threads
    return -1, with errno set to ECHILD."
    
    `getProcessExitCode` was handling the ECHILD case by returning 1, but
    `waitForProcess` was returning (-1) in all cases. For consistency this
    commit follows the approach in getProcessExitCode, returning 1 to the
    caller of c_waitForProcess if errno is ECHILD, thus avoiding throwing
    an exception in the calling code.


>---------------------------------------------------------------

5b99d45103d1edf6f596c353f548221d897db4cf
 cbits/runProcess.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/cbits/runProcess.c b/cbits/runProcess.c
index ae184c8..1e97ad1 100644
--- a/cbits/runProcess.c
+++ b/cbits/runProcess.c
@@ -425,6 +425,11 @@ int waitForProcess (ProcHandle handle, int *pret)
 
     if (waitpid(handle, &wstat, 0) < 0)
     {
+        if (errno == ECHILD)
+        {
+            *pret = 0;
+            return 1;
+        }
         return -1;
     }
 



More information about the ghc-commits mailing list