diff options
author | Joey Hess <joey@kitenet.net> | 2014-04-08 14:02:25 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-04-08 14:02:25 -0400 |
commit | 9b09962ee86ec7531d7ca946e62ccf6a48a67399 (patch) | |
tree | 13449e83e80b6e1b788c0e0996b0412038579340 /Utility | |
parent | f2426676defafecc904234de3522f57ebf7ab19d (diff) |
remotedaemon: avoid extraneous stdout output
Diffstat (limited to 'Utility')
-rw-r--r-- | Utility/SimpleProtocol.hs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/Utility/SimpleProtocol.hs b/Utility/SimpleProtocol.hs index 9cc25bc91..1119cd986 100644 --- a/Utility/SimpleProtocol.hs +++ b/Utility/SimpleProtocol.hs @@ -16,12 +16,13 @@ module Utility.SimpleProtocol ( parse1, parse2, parse3, + ioHandles, ) where -import Control.Applicative import Data.Char +import GHC.IO.Handle -import Utility.Misc +import Common -- Messages that can be sent. class Sendable m where @@ -73,3 +74,17 @@ parse3 mk s = mk <$> deserialize p1 <*> deserialize p2 <*> deserialize p3 splitWord :: String -> (String, String) splitWord = separate isSpace + +{- When a program speaks a simple protocol over stdio, any other output + - to stdout (or anything that attempts to read from stdin) + - will mess up the protocol. To avoid that, close stdin, and + - and duplicate stderr to stdout. Return two new handles + - that are duplicates of the original (stdin, stdout). -} +ioHandles :: IO (Handle, Handle) +ioHandles = do + readh <- hDuplicate stdin + writeh <- hDuplicate stdout + nullh <- openFile devNull ReadMode + nullh `hDuplicateTo` stdin + stderr `hDuplicateTo` stdout + return (readh, writeh) |