diff options
| author | Joey Hess <joey@kitenet.net> | 2014-05-10 11:13:47 -0300 |
|---|---|---|
| committer | Joey Hess <joey@kitenet.net> | 2014-05-10 11:13:47 -0300 |
| commit | eb6e6fe11290971b37a18d9a78f6d9b78228c06f (patch) | |
| tree | 5c7669b6ce12a8e7c95e918e69548de31eb4fba7 /Propellor/SimpleSh.hs | |
| parent | 6088df9105a10ef446cc236982c2e30857182a84 (diff) | |
| parent | d7ad05acaaf05c7af066c1d41f3e70e61a9bec96 (diff) | |
Merge branch 'joeyconfig'
Diffstat (limited to 'Propellor/SimpleSh.hs')
| -rw-r--r-- | Propellor/SimpleSh.hs | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/Propellor/SimpleSh.hs b/Propellor/SimpleSh.hs index 73ff41ae..d99268d1 100644 --- a/Propellor/SimpleSh.hs +++ b/Propellor/SimpleSh.hs @@ -35,14 +35,7 @@ simpleSh namedpipe = do maybe noop (run h) . readish =<< hGetLine h where run h (Cmd cmd params) = do - let p = (proc cmd params) - { std_in = Inherit - , std_out = CreatePipe - , std_err = CreatePipe - } - (Nothing, Just outh, Just errh, pid) <- createProcess p chan <- newChan - let runwriter = do v <- readChan chan hPutStrLn h (show v) @@ -52,20 +45,28 @@ simpleSh namedpipe = do _ -> runwriter writer <- async runwriter - let mkreader t from = maybe noop (const $ mkreader t from) - =<< catchMaybeIO (writeChan chan . t =<< hGetLine from) - void $ concurrently - (mkreader StdoutLine outh) - (mkreader StderrLine errh) + flip catchIO (\_e -> writeChan chan Done) $ do + let p = (proc cmd params) + { std_in = Inherit + , std_out = CreatePipe + , std_err = CreatePipe + } + (Nothing, Just outh, Just errh, pid) <- createProcess p + + let mkreader t from = maybe noop (const $ mkreader t from) + =<< catchMaybeIO (writeChan chan . t =<< hGetLine from) + void $ concurrently + (mkreader StdoutLine outh) + (mkreader StderrLine errh) - void $ tryIO $ waitForProcess pid + void $ tryIO $ waitForProcess pid - writeChan chan Done + writeChan chan Done - wait writer + hClose outh + hClose errh - hClose outh - hClose errh + wait writer hClose h simpleShClient :: FilePath -> String -> [String] -> ([Resp] -> IO a) -> IO a |
