aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2018-08-03 18:12:28 +0200
committerEelco Dolstra <edolstra@gmail.com>2018-08-03 21:20:38 +0200
commit4e7d5f660cec6da3a432c726dfe7a579c7581c79 (patch)
treed845533d968bc44a0bb7fcb842ddd31ce40d2d16 /src
parente268bbc05435d8121275136934a594fc70a73da9 (diff)
SSHMaster: Bypass SSH when connecting to localhost
This is primarily useful for testing since it removes the need to have SSH working.
Diffstat (limited to 'src')
-rw-r--r--src/libstore/ssh.cc22
-rw-r--r--src/libstore/ssh.hh1
2 files changed, 16 insertions, 7 deletions
diff --git a/src/libstore/ssh.cc b/src/libstore/ssh.cc
index 033c58093..5e0e44935 100644
--- a/src/libstore/ssh.cc
+++ b/src/libstore/ssh.cc
@@ -4,8 +4,9 @@ namespace nix {
SSHMaster::SSHMaster(const std::string & host, const std::string & keyFile, bool useMaster, bool compress, int logFD)
: host(host)
+ , fakeSSH(host == "localhost")
, keyFile(keyFile)
- , useMaster(useMaster)
+ , useMaster(useMaster && !fakeSSH)
, compress(compress)
, logFD(logFD)
{
@@ -45,12 +46,19 @@ std::unique_ptr<SSHMaster::Connection> SSHMaster::startCommand(const std::string
if (logFD != -1 && dup2(logFD, STDERR_FILENO) == -1)
throw SysError("duping over stderr");
- Strings args = { "ssh", host.c_str(), "-x", "-a" };
- addCommonSSHOpts(args);
- if (socketPath != "")
- args.insert(args.end(), {"-S", socketPath});
- if (verbosity >= lvlChatty)
- args.push_back("-v");
+ Strings args;
+
+ if (fakeSSH) {
+ args = { "bash", "-c" };
+ } else {
+ args = { "ssh", host.c_str(), "-x", "-a" };
+ addCommonSSHOpts(args);
+ if (socketPath != "")
+ args.insert(args.end(), {"-S", socketPath});
+ if (verbosity >= lvlChatty)
+ args.push_back("-v");
+ }
+
args.push_back(command);
execvp(args.begin()->c_str(), stringsToCharPtrs(args).data());
diff --git a/src/libstore/ssh.hh b/src/libstore/ssh.hh
index 1268e6d00..4f0f0bd29 100644
--- a/src/libstore/ssh.hh
+++ b/src/libstore/ssh.hh
@@ -10,6 +10,7 @@ class SSHMaster
private:
const std::string host;
+ bool fakeSSH;
const std::string keyFile;
const bool useMaster;
const bool compress;