From c6a020ad1f84ec057291e02a54de2b87091e1e74 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 21 Jul 2013 14:14:54 -0400 Subject: [PATCH] stop cached ssh connection w/o needing to look up host and port Turns out that with -O stop -S socketfile, ssh does not need the real hostname, or port to be specificed. This is because it simply talks to the ssh behind the socket and tells it to stop. So, can eliminate the conversion back from a socketfile to host and port. Which will allow using shorter filenames for sockets in the future. --- Annex/Ssh.hs | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/Annex/Ssh.hs b/Annex/Ssh.hs index 940cbb5a7b..397fdb75c2 100644 --- a/Annex/Ssh.hs +++ b/Annex/Ssh.hs @@ -51,17 +51,18 @@ sshInfo (host, port) = go =<< sshCacheDir go (Just dir) = do let socketfile = dir hostport2socket host port if valid_unix_socket_path socketfile - then return (Just socketfile, cacheparams socketfile) + then return (Just socketfile, sshConnectionCachingParams socketfile) else do socketfile' <- liftIO $ relPathCwdToFile socketfile if valid_unix_socket_path socketfile' - then return (Just socketfile', cacheparams socketfile') + then return (Just socketfile', sshConnectionCachingParams socketfile') else return (Nothing, []) - cacheparams :: FilePath -> [CommandParam] - cacheparams socketfile = - [ Param "-S", Param socketfile - , Params "-o ControlMaster=auto -o ControlPersist=yes" - ] + +sshConnectionCachingParams :: FilePath -> [CommandParam] +sshConnectionCachingParams socketfile = + [ Param "-S", Param socketfile + , Params "-o ControlMaster=auto -o ControlPersist=yes" + ] {- ssh connection caching creates sockets, so will not work on a - crippled filesystem. A GIT_ANNEX_TMP_DIR can be provided to use @@ -116,14 +117,13 @@ sshCleanup = go =<< sshCacheDir stopssh socketfile #endif stopssh socketfile = do - let (host, port) = socket2hostport socketfile - (_, params) <- sshInfo (host, port) + let params = sshConnectionCachingParams socketfile -- "ssh -O stop" is noisy on stderr even with -q void $ liftIO $ catchMaybeIO $ withQuietOutput createProcessSuccess $ proc "ssh" $ toCommand $ [ Params "-O stop" - ] ++ params ++ [Param host] + ] ++ params ++ [Param "any"] -- Cannot remove the lock file; other processes may -- be waiting on our exclusive lock to use it. @@ -131,13 +131,6 @@ hostport2socket :: String -> Maybe Integer -> FilePath hostport2socket host Nothing = host hostport2socket host (Just port) = host ++ "!" ++ show port -socket2hostport :: FilePath -> (String, Maybe Integer) -socket2hostport socket - | null p = (h, Nothing) - | otherwise = (h, readish p) - where - (h, p) = separate (== '!') $ takeFileName socket - socket2lock :: FilePath -> FilePath socket2lock socket = socket ++ lockExt