From 19b87f73960adbab2625e0c3c0385d79444e1676 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 3 Jan 2022 12:54:40 -0400 Subject: [PATCH] avoid no longer necessary piping of ssh stderr for p2pstdio This was needed when supporting old git-annex-shell that do not support p2pstdio yet, in order to cleanly fall back to the old interface without error messages being displayed. That is no longer supported, so simplify to not intercept error messages. Sponsored-by: Dartmouth College's DANDI project --- Remote/Helper/Ssh.hs | 43 ++++++++----------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/Remote/Helper/Ssh.hs b/Remote/Helper/Ssh.hs index a33c2c1bb5..32287b7c14 100644 --- a/Remote/Helper/Ssh.hs +++ b/Remote/Helper/Ssh.hs @@ -1,6 +1,6 @@ {- git-annex remote access with ssh and git-annex-shell - - - Copyright 2011-2018 Joey Hess + - Copyright 2011-2022 Joey Hess - - Licensed under the GNU AGPL version 3 or higher. -} @@ -27,7 +27,6 @@ import qualified P2P.IO as P2P import qualified P2P.Annex as P2P import Control.Concurrent.STM -import Control.Concurrent.Async toRepo :: ConsumeStdin -> Git.Repo -> RemoteGitConfig -> SshCommand -> Annex (FilePath, [CommandParam]) toRepo cs r gc remotecmd = do @@ -178,18 +177,15 @@ rsyncParams r direction = do gc = gitconfig r -- A connection over ssh to git-annex shell speaking the P2P protocol. -type P2PSshConnection = P2P.ClosableConnection - (P2P.RunState, P2P.P2PConnection, ProcessHandle, TVar StderrHandlerState) - -data StderrHandlerState = DiscardStderr | DisplayStderr | EndStderrHandler +type P2PSshConnection = P2P.ClosableConnection + (P2P.RunState, P2P.P2PConnection, ProcessHandle) closeP2PSshConnection :: P2PSshConnection -> IO (P2PSshConnection, Maybe ExitCode) closeP2PSshConnection P2P.ClosedConnection = return (P2P.ClosedConnection, Nothing) -closeP2PSshConnection (P2P.OpenConnection (_st, conn, pid, stderrhandlerst)) = +closeP2PSshConnection (P2P.OpenConnection (_st, conn, pid)) = -- mask async exceptions, avoid cleanup being interrupted uninterruptibleMask_ $ do P2P.closeConnection conn - atomically $ writeTVar stderrhandlerst EndStderrHandler exitcode <- waitForProcess pid return (P2P.ClosedConnection, Just exitcode) @@ -244,11 +240,10 @@ openP2PSshConnection r connpool = do Just (cmd, params) -> start cmd params =<< getRepo r where start cmd params repo = liftIO $ do - (Just from, Just to, Just err, pid) <- createProcess $ + (Just from, Just to, Nothing, pid) <- createProcess $ (proc cmd (toCommand params)) { std_in = CreatePipe , std_out = CreatePipe - , std_err = CreatePipe } pidnum <- getPid pid let conn = P2P.P2PConnection @@ -259,17 +254,14 @@ openP2PSshConnection r connpool = do , P2P.connIdent = P2P.ConnIdent $ Just $ "ssh connection " ++ show pidnum } - stderrhandlerst <- newStderrHandler err pid runst <- P2P.mkRunState P2P.Client - let c = P2P.OpenConnection (runst, conn, pid, stderrhandlerst) + let c = P2P.OpenConnection (runst, conn, pid) -- When the connection is successful, the remote -- will send an AUTH_SUCCESS with its uuid. let proto = P2P.postAuth $ P2P.negotiateProtocolVersion P2P.maxProtocolVersion tryNonAsync (P2P.runNetProto runst conn proto) >>= \case - Right (Right (Just theiruuid)) | theiruuid == uuid r -> do - atomically $ - writeTVar stderrhandlerst DisplayStderr + Right (Right (Just theiruuid)) | theiruuid == uuid r -> return $ Just c _ -> do (cclosed, exitcode) <- closeP2PSshConnection c @@ -284,25 +276,6 @@ openP2PSshConnection r connpool = do modifyTVar' connpool $ maybe (Just P2PSshUnsupported) Just -newStderrHandler :: Handle -> ProcessHandle -> IO (TVar StderrHandlerState) -newStderrHandler errh ph = do - -- stderr from git-annex-shell p2pstdio is initially discarded - -- because old versions don't support the command. Once it's known - -- to be running, this is changed to DisplayStderr. - v <- newTVarIO DiscardStderr - void $ async $ go v - return v - where - go v = do - hGetLineUntilExitOrEOF ph errh >>= \case - Nothing -> hClose errh - Just l -> atomically (readTVar v) >>= \case - DiscardStderr -> go v - DisplayStderr -> do - hPutStrLn stderr l - go v - EndStderrHandler -> hClose errh - -- Runs a P2P Proto action on a remote when it supports that, -- otherwise the fallback action. runProto :: Remote -> P2PSshConnectionPool -> Annex a -> P2P.Proto a -> Annex (Maybe a) @@ -319,7 +292,7 @@ runProto r connpool onerr proto = Just <$> runProtoConn :: P2P.Proto a -> P2PSshConnection -> Annex (P2PSshConnection, Maybe a) runProtoConn _ P2P.ClosedConnection = return (P2P.ClosedConnection, Nothing) -runProtoConn a conn@(P2P.OpenConnection (runst, c, _, _)) = do +runProtoConn a conn@(P2P.OpenConnection (runst, c, _)) = do P2P.runFullProto runst c a >>= \case Right r -> return (conn, Just r) -- When runFullProto fails, the connection is no longer