mirror of
https://github.com/NixOS/nix.git
synced 2025-11-15 23:12:44 +01:00
Apply clang-format universally.
* It is tough to contribute to a project that doesn't use a formatter, * It is extra hard to contribute to a project which has configured the formatter, but ignores it for some files * Code formatting makes it harder to hide obscure / weird bugs by accident or on purpose, Let's rip the bandaid off? Note that PRs currently in flight should be able to be merged relatively easily by applying `clang-format` to their tip prior to merge.
This commit is contained in:
parent
41bf87ec70
commit
e4f62e4608
587 changed files with 23258 additions and 23135 deletions
|
|
@ -21,7 +21,9 @@ SSHMaster::SSHMaster(
|
|||
std::string_view host,
|
||||
std::string_view keyFile,
|
||||
std::string_view sshPublicHostKey,
|
||||
bool useMaster, bool compress, Descriptor logFD)
|
||||
bool useMaster,
|
||||
bool compress,
|
||||
Descriptor logFD)
|
||||
: host(host)
|
||||
, fakeSSH(host == "localhost")
|
||||
, keyFile(keyFile)
|
||||
|
|
@ -72,11 +74,12 @@ void SSHMaster::addCommonSSHOpts(Strings & args)
|
|||
args.push_back("-oLocalCommand=echo started");
|
||||
}
|
||||
|
||||
bool SSHMaster::isMasterRunning() {
|
||||
bool SSHMaster::isMasterRunning()
|
||||
{
|
||||
Strings args = {"-O", "check", host};
|
||||
addCommonSSHOpts(args);
|
||||
|
||||
auto res = runProgram(RunOptions {.program = "ssh", .args = args, .mergeStderrToStdout = true});
|
||||
auto res = runProgram(RunOptions{.program = "ssh", .args = args, .mergeStderrToStdout = true});
|
||||
return res.first == 0;
|
||||
}
|
||||
|
||||
|
|
@ -101,8 +104,7 @@ Strings createSSHEnv()
|
|||
return r;
|
||||
}
|
||||
|
||||
std::unique_ptr<SSHMaster::Connection> SSHMaster::startCommand(
|
||||
Strings && command, Strings && extraSshArgs)
|
||||
std::unique_ptr<SSHMaster::Connection> SSHMaster::startCommand(Strings && command, Strings && extraSshArgs)
|
||||
{
|
||||
#ifdef _WIN32 // TODO re-enable on Windows, once we can start processes.
|
||||
throw UnimplementedError("cannot yet SSH on windows because spawning processes is not yet implemented");
|
||||
|
|
@ -122,40 +124,41 @@ std::unique_ptr<SSHMaster::Connection> SSHMaster::startCommand(
|
|||
loggerSuspension = std::make_unique<Logger::Suspension>(logger->suspend());
|
||||
}
|
||||
|
||||
conn->sshPid = startProcess([&]() {
|
||||
restoreProcessContext();
|
||||
conn->sshPid = startProcess(
|
||||
[&]() {
|
||||
restoreProcessContext();
|
||||
|
||||
close(in.writeSide.get());
|
||||
close(out.readSide.get());
|
||||
close(in.writeSide.get());
|
||||
close(out.readSide.get());
|
||||
|
||||
if (dup2(in.readSide.get(), STDIN_FILENO) == -1)
|
||||
throw SysError("duping over stdin");
|
||||
if (dup2(out.writeSide.get(), STDOUT_FILENO) == -1)
|
||||
throw SysError("duping over stdout");
|
||||
if (logFD != -1 && dup2(logFD, STDERR_FILENO) == -1)
|
||||
throw SysError("duping over stderr");
|
||||
if (dup2(in.readSide.get(), STDIN_FILENO) == -1)
|
||||
throw SysError("duping over stdin");
|
||||
if (dup2(out.writeSide.get(), STDOUT_FILENO) == -1)
|
||||
throw SysError("duping over stdout");
|
||||
if (logFD != -1 && dup2(logFD, STDERR_FILENO) == -1)
|
||||
throw SysError("duping over stderr");
|
||||
|
||||
Strings args;
|
||||
Strings args;
|
||||
|
||||
if (!fakeSSH) {
|
||||
args = { "ssh", host.c_str(), "-x" };
|
||||
addCommonSSHOpts(args);
|
||||
if (socketPath != "")
|
||||
args.insert(args.end(), {"-S", socketPath});
|
||||
if (verbosity >= lvlChatty)
|
||||
args.push_back("-v");
|
||||
args.splice(args.end(), std::move(extraSshArgs));
|
||||
args.push_back("--");
|
||||
}
|
||||
if (!fakeSSH) {
|
||||
args = {"ssh", host.c_str(), "-x"};
|
||||
addCommonSSHOpts(args);
|
||||
if (socketPath != "")
|
||||
args.insert(args.end(), {"-S", socketPath});
|
||||
if (verbosity >= lvlChatty)
|
||||
args.push_back("-v");
|
||||
args.splice(args.end(), std::move(extraSshArgs));
|
||||
args.push_back("--");
|
||||
}
|
||||
|
||||
args.splice(args.end(), std::move(command));
|
||||
auto env = createSSHEnv();
|
||||
nix::execvpe(args.begin()->c_str(), stringsToCharPtrs(args).data(), stringsToCharPtrs(env).data());
|
||||
|
||||
// could not exec ssh/bash
|
||||
throw SysError("unable to execute '%s'", args.front());
|
||||
}, options);
|
||||
args.splice(args.end(), std::move(command));
|
||||
auto env = createSSHEnv();
|
||||
nix::execvpe(args.begin()->c_str(), stringsToCharPtrs(args).data(), stringsToCharPtrs(env).data());
|
||||
|
||||
// could not exec ssh/bash
|
||||
throw SysError("unable to execute '%s'", args.front());
|
||||
},
|
||||
options);
|
||||
|
||||
in.readSide = INVALID_DESCRIPTOR;
|
||||
out.writeSide = INVALID_DESCRIPTOR;
|
||||
|
|
@ -166,7 +169,8 @@ std::unique_ptr<SSHMaster::Connection> SSHMaster::startCommand(
|
|||
std::string reply;
|
||||
try {
|
||||
reply = readLine(out.readSide.get());
|
||||
} catch (EndOfFile & e) { }
|
||||
} catch (EndOfFile & e) {
|
||||
}
|
||||
|
||||
if (reply != "started") {
|
||||
printTalkative("SSH stdout first line: %s", reply);
|
||||
|
|
@ -185,11 +189,13 @@ std::unique_ptr<SSHMaster::Connection> SSHMaster::startCommand(
|
|||
|
||||
Path SSHMaster::startMaster()
|
||||
{
|
||||
if (!useMaster) return "";
|
||||
if (!useMaster)
|
||||
return "";
|
||||
|
||||
auto state(state_.lock());
|
||||
|
||||
if (state->sshMaster != INVALID_DESCRIPTOR) return state->socketPath;
|
||||
if (state->sshMaster != INVALID_DESCRIPTOR)
|
||||
return state->socketPath;
|
||||
|
||||
state->socketPath = (Path) *state->tmpDir + "/ssh.sock";
|
||||
|
||||
|
|
@ -204,30 +210,33 @@ Path SSHMaster::startMaster()
|
|||
if (isMasterRunning())
|
||||
return state->socketPath;
|
||||
|
||||
state->sshMaster = startProcess([&]() {
|
||||
restoreProcessContext();
|
||||
state->sshMaster = startProcess(
|
||||
[&]() {
|
||||
restoreProcessContext();
|
||||
|
||||
close(out.readSide.get());
|
||||
close(out.readSide.get());
|
||||
|
||||
if (dup2(out.writeSide.get(), STDOUT_FILENO) == -1)
|
||||
throw SysError("duping over stdout");
|
||||
if (dup2(out.writeSide.get(), STDOUT_FILENO) == -1)
|
||||
throw SysError("duping over stdout");
|
||||
|
||||
Strings args = { "ssh", host.c_str(), "-M", "-N", "-S", state->socketPath };
|
||||
if (verbosity >= lvlChatty)
|
||||
args.push_back("-v");
|
||||
addCommonSSHOpts(args);
|
||||
auto env = createSSHEnv();
|
||||
nix::execvpe(args.begin()->c_str(), stringsToCharPtrs(args).data(), stringsToCharPtrs(env).data());
|
||||
Strings args = {"ssh", host.c_str(), "-M", "-N", "-S", state->socketPath};
|
||||
if (verbosity >= lvlChatty)
|
||||
args.push_back("-v");
|
||||
addCommonSSHOpts(args);
|
||||
auto env = createSSHEnv();
|
||||
nix::execvpe(args.begin()->c_str(), stringsToCharPtrs(args).data(), stringsToCharPtrs(env).data());
|
||||
|
||||
throw SysError("unable to execute '%s'", args.front());
|
||||
}, options);
|
||||
throw SysError("unable to execute '%s'", args.front());
|
||||
},
|
||||
options);
|
||||
|
||||
out.writeSide = INVALID_DESCRIPTOR;
|
||||
|
||||
std::string reply;
|
||||
try {
|
||||
reply = readLine(out.readSide.get());
|
||||
} catch (EndOfFile & e) { }
|
||||
} catch (EndOfFile & e) {
|
||||
}
|
||||
|
||||
if (reply != "started") {
|
||||
printTalkative("SSH master stdout first line: %s", reply);
|
||||
|
|
@ -254,4 +263,4 @@ void SSHMaster::Connection::trySetBufferSize(size_t size)
|
|||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace nix
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue