mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 12:06:01 +01:00
Merge pull request #13902 from NixOS/ssh-master-deadlock
Fix deadlock in SSHMaster::addCommonSSHOpts()
This commit is contained in:
commit
25d3c197b8
2 changed files with 6 additions and 7 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
///@file
|
///@file
|
||||||
|
|
||||||
|
#include "nix/util/ref.hh"
|
||||||
#include "nix/util/sync.hh"
|
#include "nix/util/sync.hh"
|
||||||
#include "nix/util/url.hh"
|
#include "nix/util/url.hh"
|
||||||
#include "nix/util/processes.hh"
|
#include "nix/util/processes.hh"
|
||||||
|
|
@ -26,12 +27,13 @@ private:
|
||||||
const bool compress;
|
const bool compress;
|
||||||
const Descriptor logFD;
|
const Descriptor logFD;
|
||||||
|
|
||||||
|
const ref<const AutoDelete> tmpDir;
|
||||||
|
|
||||||
struct State
|
struct State
|
||||||
{
|
{
|
||||||
#ifndef _WIN32 // TODO re-enable on Windows, once we can start processes.
|
#ifndef _WIN32 // TODO re-enable on Windows, once we can start processes.
|
||||||
Pid sshMaster;
|
Pid sshMaster;
|
||||||
#endif
|
#endif
|
||||||
std::unique_ptr<AutoDelete> tmpDir;
|
|
||||||
Path socketPath;
|
Path socketPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,23 +84,20 @@ SSHMaster::SSHMaster(
|
||||||
, useMaster(useMaster && !fakeSSH)
|
, useMaster(useMaster && !fakeSSH)
|
||||||
, compress(compress)
|
, compress(compress)
|
||||||
, logFD(logFD)
|
, logFD(logFD)
|
||||||
|
, tmpDir(make_ref<AutoDelete>(createTempDir("", "nix", 0700)))
|
||||||
{
|
{
|
||||||
checkValidAuthority(authority);
|
checkValidAuthority(authority);
|
||||||
auto state(state_.lock());
|
|
||||||
state->tmpDir = std::make_unique<AutoDelete>(createTempDir("", "nix", 0700));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSHMaster::addCommonSSHOpts(Strings & args)
|
void SSHMaster::addCommonSSHOpts(Strings & args)
|
||||||
{
|
{
|
||||||
auto state(state_.lock());
|
|
||||||
|
|
||||||
auto sshArgs = getNixSshOpts();
|
auto sshArgs = getNixSshOpts();
|
||||||
args.insert(args.end(), sshArgs.begin(), sshArgs.end());
|
args.insert(args.end(), sshArgs.begin(), sshArgs.end());
|
||||||
|
|
||||||
if (!keyFile.empty())
|
if (!keyFile.empty())
|
||||||
args.insert(args.end(), {"-i", keyFile});
|
args.insert(args.end(), {"-i", keyFile});
|
||||||
if (!sshPublicHostKey.empty()) {
|
if (!sshPublicHostKey.empty()) {
|
||||||
std::filesystem::path fileName = state->tmpDir->path() / "host-key";
|
std::filesystem::path fileName = tmpDir->path() / "host-key";
|
||||||
writeFile(fileName.string(), authority.host + " " + sshPublicHostKey + "\n");
|
writeFile(fileName.string(), authority.host + " " + sshPublicHostKey + "\n");
|
||||||
args.insert(args.end(), {"-oUserKnownHostsFile=" + fileName.string()});
|
args.insert(args.end(), {"-oUserKnownHostsFile=" + fileName.string()});
|
||||||
}
|
}
|
||||||
|
|
@ -241,7 +238,7 @@ Path SSHMaster::startMaster()
|
||||||
if (state->sshMaster != INVALID_DESCRIPTOR)
|
if (state->sshMaster != INVALID_DESCRIPTOR)
|
||||||
return state->socketPath;
|
return state->socketPath;
|
||||||
|
|
||||||
state->socketPath = (Path) *state->tmpDir + "/ssh.sock";
|
state->socketPath = (Path) *tmpDir + "/ssh.sock";
|
||||||
|
|
||||||
Pipe out;
|
Pipe out;
|
||||||
out.create();
|
out.create();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue