Skip to content

Commit d13c945

Browse files
committed
Document throwing of UserInterrupt when ending Ctrl-C delegation
1 parent 8227693 commit d13c945

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

System/Process.hs

+9-2
Original file line numberDiff line numberDiff line change
@@ -676,14 +676,16 @@ getCurrentPid =
676676
-- waitForProcess
677677

678678
{- | Waits for the specified process to terminate, and returns its exit code.
679+
On Unix systems, may throw 'UserInterrupt' when using 'delegate_ctlc'.
679680
680681
GHC Note: in order to call @waitForProcess@ without blocking all the
681682
other threads in the system, you must compile the program with
682683
@-threaded@.
683684
684685
Note that it is safe to call @waitForProcess@ for the same process in multiple
685686
threads. When the process ends, threads blocking on this call will wake in
686-
FIFO order.
687+
FIFO order. When using 'delegate_ctlc' and the process is interrupted, only
688+
the first waiting thread will throw 'UserInterrupt'.
687689
688690
(/Since: 1.2.0.0/) On Unix systems, a negative value @'ExitFailure' -/signum/@
689691
indicates that the child was terminated by signal @/signum/@.
@@ -710,6 +712,8 @@ waitForProcess ph@(ProcessHandle _ delegating_ctlc _) = lockWaitpid $ do
710712
OpenHandle ph' -> do
711713
closePHANDLE ph'
712714
return (ClosedHandle e, (e, True))
715+
-- endDelegateControlC after closing the handle, since it
716+
-- may throw UserInterrupt
713717
when (was_open && delegating_ctlc) $
714718
endDelegateControlC e
715719
return e'
@@ -759,7 +763,8 @@ still running, 'Nothing' is returned. If the process has exited, then
759763
@'Just' e@ is returned where @e@ is the exit code of the process.
760764
761765
On Unix systems, see 'waitForProcess' for the meaning of exit codes
762-
when the process died as the result of a signal.
766+
when the process died as the result of a signal. May throw
767+
'UserInterrupt' when using 'delegate_ctlc'.
763768
-}
764769

765770
getProcessExitCode :: ProcessHandle -> IO (Maybe ExitCode)
@@ -782,6 +787,8 @@ getProcessExitCode ph@(ProcessHandle _ delegating_ctlc _) = tryLockWaitpid $ do
782787
let e | code == 0 = ExitSuccess
783788
| otherwise = ExitFailure (fromIntegral code)
784789
return (ClosedHandle e, (Just e, True))
790+
-- endDelegateControlC after closing the handle, since it
791+
-- may throw UserInterrupt
785792
case m_e of
786793
Just e | was_open && delegating_ctlc -> endDelegateControlC e
787794
_ -> return ()

0 commit comments

Comments
 (0)