convert to use hGetLineUntilExitOrEOF
It looks to me like the old code would have already dealt with the case of ssh starting a ssh daemon that inherits stderr and keeps it open. The ender thread closed the handle, which would unblock the other thread and let it exit. Using hGetLineUntilExitOrEOF makes this more explicit that it's dealt with and simplifies the code.
This commit is contained in:
parent
66497d39b3
commit
613455e059
1 changed files with 12 additions and 21 deletions
|
@ -28,7 +28,6 @@ import qualified P2P.Annex as P2P
|
||||||
|
|
||||||
import Control.Concurrent.STM
|
import Control.Concurrent.STM
|
||||||
import Control.Concurrent.Async
|
import Control.Concurrent.Async
|
||||||
import qualified Data.ByteString as B
|
|
||||||
|
|
||||||
toRepo :: ConsumeStdin -> Git.Repo -> RemoteGitConfig -> SshCommand -> Annex (FilePath, [CommandParam])
|
toRepo :: ConsumeStdin -> Git.Repo -> RemoteGitConfig -> SshCommand -> Annex (FilePath, [CommandParam])
|
||||||
toRepo cs r gc remotecmd = do
|
toRepo cs r gc remotecmd = do
|
||||||
|
@ -272,7 +271,7 @@ openP2PSshConnection r connpool = do
|
||||||
, P2P.connIdent = P2P.ConnIdent $
|
, P2P.connIdent = P2P.ConnIdent $
|
||||||
Just $ "ssh connection " ++ show pidnum
|
Just $ "ssh connection " ++ show pidnum
|
||||||
}
|
}
|
||||||
stderrhandlerst <- newStderrHandler err
|
stderrhandlerst <- newStderrHandler err pid
|
||||||
runst <- P2P.mkRunState P2P.Client
|
runst <- P2P.mkRunState P2P.Client
|
||||||
let c = P2P.OpenConnection (runst, conn, pid, stderrhandlerst)
|
let c = P2P.OpenConnection (runst, conn, pid, stderrhandlerst)
|
||||||
-- When the connection is successful, the remote
|
-- When the connection is successful, the remote
|
||||||
|
@ -301,32 +300,24 @@ openP2PSshConnection r connpool = do
|
||||||
modifyTVar' connpool $
|
modifyTVar' connpool $
|
||||||
maybe (Just P2PSshUnsupported) Just
|
maybe (Just P2PSshUnsupported) Just
|
||||||
|
|
||||||
newStderrHandler :: Handle -> IO (TVar StderrHandlerState)
|
newStderrHandler :: Handle -> ProcessHandle -> IO (TVar StderrHandlerState)
|
||||||
newStderrHandler errh = do
|
newStderrHandler errh ph = do
|
||||||
-- stderr from git-annex-shell p2pstdio is initially discarded
|
-- stderr from git-annex-shell p2pstdio is initially discarded
|
||||||
-- because old versions don't support the command. Once it's known
|
-- because old versions don't support the command. Once it's known
|
||||||
-- to be running, this is changed to DisplayStderr.
|
-- to be running, this is changed to DisplayStderr.
|
||||||
v <- newTVarIO DiscardStderr
|
v <- newTVarIO DiscardStderr
|
||||||
p <- async $ go v
|
void $ async $ go v
|
||||||
void $ async $ ender p v
|
|
||||||
return v
|
return v
|
||||||
where
|
where
|
||||||
go v = do
|
go v = do
|
||||||
l <- B.hGetLine errh
|
hGetLineUntilExitOrEOF ph errh >>= \case
|
||||||
atomically (readTVar v) >>= \case
|
Nothing -> hClose errh
|
||||||
DiscardStderr -> go v
|
Just l -> atomically (readTVar v) >>= \case
|
||||||
DisplayStderr -> do
|
DiscardStderr -> go v
|
||||||
B.hPut stderr l
|
DisplayStderr -> do
|
||||||
go v
|
hPutStrLn stderr l
|
||||||
EndStderrHandler -> return ()
|
go v
|
||||||
|
EndStderrHandler -> hClose errh
|
||||||
ender p v = do
|
|
||||||
atomically $ do
|
|
||||||
readTVar v >>= \case
|
|
||||||
EndStderrHandler -> return ()
|
|
||||||
_ -> retry
|
|
||||||
hClose errh
|
|
||||||
cancel p
|
|
||||||
|
|
||||||
-- Runs a P2P Proto action on a remote when it supports that,
|
-- Runs a P2P Proto action on a remote when it supports that,
|
||||||
-- otherwise the fallback action.
|
-- otherwise the fallback action.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue