summaryrefslogtreecommitdiff
path: root/src/Propellor
diff options
context:
space:
mode:
authorJoey Hess2017-07-13 12:29:01 -0400
committerJoey Hess2017-07-13 12:29:01 -0400
commit53fe5ffaac4a243bb9fd3cf0e757128150a6a199 (patch)
treec153352323c478cc2cb832681225439c680f0b03 /src/Propellor
parent1555c6f88a0446d3e29149eff8315817696731e1 (diff)
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.
Diffstat (limited to 'src/Propellor')
-rw-r--r--src/Propellor/Spin.hs22
1 files changed, 6 insertions, 16 deletions
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