From da8b3777521b99b6cff270212c5bcaebc6e0f260 Mon Sep 17 00:00:00 2001 From: Joe Cheng Date: Wed, 21 Sep 2011 14:22:16 -0700 Subject: [PATCH] Fix git-ssh hangs on Linux --- .../session/modules/SessionSourceControl.cpp | 26 +++++++++++++++++-- src/cpp/session/postback/rpostback-gitssh | 8 +++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/cpp/session/modules/SessionSourceControl.cpp b/src/cpp/session/modules/SessionSourceControl.cpp index ccd49f7927e..bd0a72e2e66 100644 --- a/src/cpp/session/modules/SessionSourceControl.cpp +++ b/src/cpp/session/modules/SessionSourceControl.cpp @@ -1558,11 +1558,30 @@ core::Error initialize() s_pVcsImpl_.reset(new VCSImpl(workingDir)); bool interceptSsh; + bool interceptAskPass; + + if (options().programMode() == kSessionProgramModeServer) + { + interceptSsh = true; + interceptAskPass = true; + } + else + { #ifdef __APPLE__ - interceptSsh = options().programMode() != kSessionProgramModeDesktop; + // Default behavior on Mac desktop works great + interceptSsh = false; + interceptAskPass = false; +#elif defined(_WIN32) + // Windows probably unlikely to have either ssh-agent or askpass + interceptSsh = true; + interceptAskPass = true; #else - interceptSsh = true; + // Everything fine on Linux except we need to detach the console + // using setsid + interceptSsh = true; + interceptAskPass = false; #endif + } if (interceptSsh) { @@ -1573,7 +1592,10 @@ core::Error initialize() if (error) return error; core::system::setenv("GIT_SSH", toBashPath(gitSshCmd)); + } + if (interceptAskPass) + { std::string sshAskCmd; error = module_context::registerPostbackHandler("askpass", postbackSSHAskPass, diff --git a/src/cpp/session/postback/rpostback-gitssh b/src/cpp/session/postback/rpostback-gitssh index c6b39516a85..e55a09349a9 100755 --- a/src/cpp/session/postback/rpostback-gitssh +++ b/src/cpp/session/postback/rpostback-gitssh @@ -17,4 +17,10 @@ set -e SSH_AGENT_SCRIPT=`$(dirname $0)/rpostback gitssh` eval "$SSH_AGENT_SCRIPT" &> /dev/null -ssh -o StrictHostKeyChecking=no $* + +unamestr=`uname` +if [[ "$unamestr" == "Linux" ]]; then + setsid ssh -o StrictHostKeyChecking=no $* +else + ssh -o StrictHostKeyChecking=no $* +fi