aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/ssh-store.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore/ssh-store.cc')
-rw-r--r--src/libstore/ssh-store.cc24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/libstore/ssh-store.cc b/src/libstore/ssh-store.cc
index cce0458c6..6f1862afa 100644
--- a/src/libstore/ssh-store.cc
+++ b/src/libstore/ssh-store.cc
@@ -7,11 +7,13 @@
namespace nix {
+static std::string uriScheme = "ssh://";
+
class SSHStore : public RemoteStore
{
public:
- SSHStore(string uri, const Params & params, size_t maxConnections = std::numeric_limits<size_t>::max());
+ SSHStore(string host, const Params & params, size_t maxConnections = std::numeric_limits<size_t>::max());
std::string getUri() override;
@@ -36,19 +38,19 @@ private:
Pid sshMaster;
- string uri;
+ string host;
Path key;
bool compress;
};
-SSHStore::SSHStore(string uri, const Params & params, size_t maxConnections)
+SSHStore::SSHStore(string host, const Params & params, size_t maxConnections)
: Store(params)
, RemoteStore(params, maxConnections)
, tmpDir(createTempDir("", "nix", true, true, 0700))
, socketPath((Path) tmpDir + "/ssh.sock")
- , uri(std::move(uri))
+ , host(std::move(host))
, key(get(params, "ssh-key", ""))
, compress(get(params, "compress", "") == "true")
{
@@ -58,7 +60,7 @@ SSHStore::SSHStore(string uri, const Params & params, size_t maxConnections)
string SSHStore::getUri()
{
- return "ssh://" + uri;
+ return uriScheme + host;
}
class ForwardSource : public Source
@@ -93,12 +95,12 @@ ref<FSAccessor> SSHStore::getFSAccessor()
ref<RemoteStore::Connection> SSHStore::openConnection()
{
if ((pid_t) sshMaster == -1) {
- auto flags = compress ? "-NMCS" : "-NMS";
sshMaster = startProcess([&]() {
+ restoreSignals();
if (key.empty())
- execlp("ssh", "ssh", flags, socketPath.c_str(), uri.c_str(), NULL);
+ execlp("ssh", "ssh", "-N", "-M", "-S", socketPath.c_str(), host.c_str(), NULL);
else
- execlp("ssh", "ssh", flags, socketPath.c_str(), "-i", key.c_str(), uri.c_str(), NULL);
+ execlp("ssh", "ssh", "-N", "-M", "-S", socketPath.c_str(), "-i", key.c_str(), host.c_str(), NULL);
throw SysError("starting ssh master");
});
}
@@ -112,7 +114,7 @@ ref<RemoteStore::Connection> SSHStore::openConnection()
throw SysError("duping over STDIN");
if (dup2(out.writeSide.get(), STDOUT_FILENO) == -1)
throw SysError("duping over STDOUT");
- execlp("ssh", "ssh", "-S", socketPath.c_str(), uri.c_str(), "nix-daemon", "--stdio", NULL);
+ execlp("ssh", "ssh", "-S", socketPath.c_str(), host.c_str(), "nix-daemon", "--stdio", NULL);
throw SysError("executing nix-daemon --stdio over ssh");
});
in.readSide = -1;
@@ -129,8 +131,8 @@ static RegisterStoreImplementation regStore([](
const std::string & uri, const Store::Params & params)
-> std::shared_ptr<Store>
{
- if (std::string(uri, 0, 6) != "ssh://") return 0;
- return std::make_shared<SSHStore>(uri.substr(6), params);
+ if (std::string(uri, 0, uriScheme.size()) != uriScheme) return 0;
+ return std::make_shared<SSHStore>(std::string(uri, uriScheme.size()), params);
});
}