Skip to content

Commit

Permalink
make rawSystemIOWithEnv close its handles
Browse files Browse the repository at this point in the history
  • Loading branch information
luite committed Oct 14, 2013
1 parent e5b0610 commit f6dae38
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Cabal/Distribution/Simple/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ import System.Directory
import System.IO
( Handle, openFile, openBinaryFile, openBinaryTempFile
, IOMode(ReadMode), hSetBinaryMode
, hGetContents, stderr, stdout, hPutStr, hFlush, hClose )
, hGetContents, stdin, stderr, stdout, hPutStr, hFlush, hClose )
import System.IO.Error as IO.Error
( isDoesNotExistError, isAlreadyExistsError
, ioeSetFileName, ioeGetFileName, ioeGetErrorString )
Expand Down Expand Up @@ -473,9 +473,15 @@ rawSystemIOWithEnv verbosity path args mcwd menv inp out err = do
, Process.std_err = mbToStd err }
unless (exitcode == ExitSuccess) $ do
debug verbosity $ path ++ " returned " ++ show exitcode
mapM_ maybeClose [inp, out, err]
return exitcode
where
-- Also taken from System.Process
maybeClose :: Maybe Handle -> IO ()
maybeClose (Just hdl)
| hdl /= stdin && hdl /= stdout && hdl /= stderr = hClose hdl
maybeClose _ = return ()

mbToStd :: Maybe Handle -> StdStream
mbToStd Nothing = Inherit
mbToStd (Just hdl) = UseHandle hdl
Expand Down

0 comments on commit f6dae38

Please sign in to comment.