about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2016-09-12T12·07-0400
committerShea Levy <shea@shealevy.com>2016-09-12T12·07-0400
commit196815f70014d9e7c3a44b66d4c1eb35aa56a282 (patch)
tree091ee4c905811d1a94ebd0f48d55dfa26340249a /src
parentab31f9986c68f575d902582ed3e176b777cb49e1 (diff)
ssh-store: Start master on-demand
Diffstat (limited to 'src')
-rw-r--r--src/libstore/ssh-store.cc21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/libstore/ssh-store.cc b/src/libstore/ssh-store.cc
index 05992bb49d6e..5166485226d9 100644
--- a/src/libstore/ssh-store.cc
+++ b/src/libstore/ssh-store.cc
@@ -37,6 +37,8 @@ private:
     Pid sshMaster;
 
     string uri;
+
+    Path key;
 };
 
 SSHStore::SSHStore(string uri, const Params & params, size_t maxConnections)
@@ -44,15 +46,8 @@ SSHStore::SSHStore(string uri, const Params & params, size_t maxConnections)
     , RemoteStore(params, maxConnections)
     , tmpDir(createTempDir("", "nix", true, true, 0700))
     , socketPath((Path) tmpDir + "/ssh.sock")
-    , sshMaster(startProcess([&]() {
-                auto key = get(params, "ssh-key", "");
-                if (key.empty())
-                    execlp("ssh", "ssh", "-N", "-M", "-S", socketPath.c_str(), uri.c_str(), NULL);
-                else
-                    execlp("ssh", "ssh", "-N", "-M", "-S", socketPath.c_str(), "-i", key.c_str(), uri.c_str(), NULL);
-                throw SysError("starting ssh master");
-      }))
     , uri(std::move(uri))
+    , key(get(params, "ssh-key", ""))
 {
 }
 
@@ -92,6 +87,16 @@ ref<FSAccessor> SSHStore::getFSAccessor()
 
 ref<RemoteStore::Connection> SSHStore::openConnection()
 {
+    if ((pid_t) sshMaster == -1) {
+        sshMaster = startProcess([&]() {
+            if (key.empty())
+                execlp("ssh", "ssh", "-N", "-M", "-S", socketPath.c_str(), uri.c_str(), NULL);
+            else
+                execlp("ssh", "ssh", "-N", "-M", "-S", socketPath.c_str(), "-i", key.c_str(), uri.c_str(), NULL);
+            throw SysError("starting ssh master");
+        });
+    }
+
     auto conn = make_ref<Connection>();
     Pipe in, out;
     in.create();