From e47e4fb7e66da3c1b00b0a56b6d05f28a1f63225 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Sat, 11 Apr 2020 13:46:51 -0400 Subject: [PATCH] FIX don't hang if one of the process we need to kill has died --- lib/XMonad/Internal/Process.hs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/XMonad/Internal/Process.hs b/lib/XMonad/Internal/Process.hs index aa7bb4d..69f0322 100644 --- a/lib/XMonad/Internal/Process.hs +++ b/lib/XMonad/Internal/Process.hs @@ -17,6 +17,8 @@ import Control.Concurrent import Control.Exception import Control.Monad +import Data.Maybe + import System.Directory import System.Exit import System.IO @@ -38,11 +40,13 @@ waitUntilExit pid = do killHandle :: ProcessHandle -> IO () killHandle ph = do - pid <- getPid ph - forM_ pid $ signalProcess sigTERM - -- this may fail if the process exits instantly and the handle - -- is destroyed by the time we get to this line (I think?) - void (try $ waitForProcess ph :: IO (Either IOException ExitCode)) + ec <- getProcessExitCode ph + unless (isJust ec) $ do + pid <- getPid ph + forM_ pid $ signalProcess sigTERM + -- this may fail if the process exits instantly and the handle + -- is destroyed by the time we get to this line (I think?) + void (try $ waitForProcess ph :: IO (Either IOException ExitCode)) withDefaultSignalHandlers :: IO a -> IO a withDefaultSignalHandlers =