From 53fe5ffaac4a243bb9fd3cf0e757128150a6a199 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 13 Jul 2017 12:29:01 -0400 Subject: finally really fixed HEAD problem My first try with a pipe was the right approach, and was almost right, except I forgot to close the write end of the pipe, and so it was inherited by the forked process, leading to deadlock. --- src/Propellor/Spin.hs | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'src/Propellor') diff --git a/src/Propellor/Spin.hs b/src/Propellor/Spin.hs index 6b6c6d69..aeaa4643 100644 --- a/src/Propellor/Spin.hs +++ b/src/Propellor/Spin.hs @@ -362,8 +362,13 @@ gitPullFromUpdateServer = req NeedGitPush gitPushMarker $ \_ -> do -- To do so, create a pipe, and forward stdin, including any -- buffered part, through it. (pread, pwrite) <- System.Posix.IO.createPipe + -- Note that there is a race between the createPipe and setting + -- CloseOnExec. Another processess forked here would inherit + -- pwrite and perhaps keep it open. However, propellor is not + -- running concurrent threads at this point, so this is ok. + setFdOption pwrite CloseOnExec True hwrite <- fdToHandle pwrite - forwarder <- async $ stdin *>*! hwrite + forwarder <- async $ stdin *>* hwrite let hin = pread hout <- dup stdOutput hClose stdout @@ -408,18 +413,3 @@ fromh *>* toh = do B.hPut toh b hFlush toh fromh *>* toh - -(*>*!) :: Handle -> Handle -> IO () -fromh *>*! toh = do - b <- B.hGetSome fromh 40960 - if B.null b - then do - hPutStrLn stderr "EOF on forwarded input" - hClose fromh - hClose toh - else do - hPutStrLn stderr "forwarding input:" - B.hPut stderr b - B.hPut toh b - hFlush toh - fromh *>*! toh -- cgit v1.2.3