SSHMaster: Bypass SSH when connecting to localhost
This is primarily useful for testing since it removes the need to have SSH working.
This commit is contained in:
parent
e268bbc054
commit
4e7d5f660c
2 changed files with 16 additions and 7 deletions
|
@ -4,8 +4,9 @@ namespace nix {
|
||||||
|
|
||||||
SSHMaster::SSHMaster(const std::string & host, const std::string & keyFile, bool useMaster, bool compress, int logFD)
|
SSHMaster::SSHMaster(const std::string & host, const std::string & keyFile, bool useMaster, bool compress, int logFD)
|
||||||
: host(host)
|
: host(host)
|
||||||
|
, fakeSSH(host == "localhost")
|
||||||
, keyFile(keyFile)
|
, keyFile(keyFile)
|
||||||
, useMaster(useMaster)
|
, useMaster(useMaster && !fakeSSH)
|
||||||
, compress(compress)
|
, compress(compress)
|
||||||
, logFD(logFD)
|
, logFD(logFD)
|
||||||
{
|
{
|
||||||
|
@ -45,12 +46,19 @@ std::unique_ptr<SSHMaster::Connection> SSHMaster::startCommand(const std::string
|
||||||
if (logFD != -1 && dup2(logFD, STDERR_FILENO) == -1)
|
if (logFD != -1 && dup2(logFD, STDERR_FILENO) == -1)
|
||||||
throw SysError("duping over stderr");
|
throw SysError("duping over stderr");
|
||||||
|
|
||||||
Strings args = { "ssh", host.c_str(), "-x", "-a" };
|
Strings args;
|
||||||
addCommonSSHOpts(args);
|
|
||||||
if (socketPath != "")
|
if (fakeSSH) {
|
||||||
args.insert(args.end(), {"-S", socketPath});
|
args = { "bash", "-c" };
|
||||||
if (verbosity >= lvlChatty)
|
} else {
|
||||||
args.push_back("-v");
|
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);
|
args.push_back(command);
|
||||||
execvp(args.begin()->c_str(), stringsToCharPtrs(args).data());
|
execvp(args.begin()->c_str(), stringsToCharPtrs(args).data());
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ class SSHMaster
|
||||||
private:
|
private:
|
||||||
|
|
||||||
const std::string host;
|
const std::string host;
|
||||||
|
bool fakeSSH;
|
||||||
const std::string keyFile;
|
const std::string keyFile;
|
||||||
const bool useMaster;
|
const bool useMaster;
|
||||||
const bool compress;
|
const bool compress;
|
||||||
|
|
Loading…
Reference in a new issue