From 196815f70014d9e7c3a44b66d4c1eb35aa56a282 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 12 Sep 2016 08:07:50 -0400 Subject: ssh-store: Start master on-demand --- src/libstore/ssh-store.cc | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src') 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 SSHStore::getFSAccessor() ref 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(); Pipe in, out; in.create(); -- cgit 1.4.1