Skip to content

Commit

Permalink
Merge pull request #1340 from NixOS/start-using-nix-ssh
Browse files Browse the repository at this point in the history
Replace `Child` with `SSHMaster::Connection`
  • Loading branch information
Ericson2314 authored Jan 23, 2024
2 parents 02e453f + 4e8fbaa commit f5c0efb
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/hydra-queue-runner/build-remote.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,13 @@
#include "util.hh"
#include "serve-protocol.hh"
#include "serve-protocol-impl.hh"
#include "ssh.hh"
#include "finally.hh"
#include "url.hh"

using namespace nix;


struct Child
{
Pid pid;
AutoCloseFD to, from;
};


static void append(Strings & dst, const Strings & src)
{
dst.insert(dst.end(), src.begin(), src.end());
Expand Down Expand Up @@ -54,7 +48,7 @@ static Strings extraStoreArgs(std::string & machine)
return result;
}

static void openConnection(Machine::ptr machine, Path tmpDir, int stderrFD, Child & child)
static void openConnection(Machine::ptr machine, Path tmpDir, int stderrFD, SSHMaster::Connection & child)
{
std::string pgmName;
Pipe to, from;
Expand Down Expand Up @@ -84,7 +78,7 @@ static void openConnection(Machine::ptr machine, Path tmpDir, int stderrFD, Chil
append(argv, extraArgs);
}

child.pid = startProcess([&]() {
child.sshPid = startProcess([&]() {
restoreProcessContext();

if (dup2(to.readSide.get(), STDIN_FILENO) == -1)
Expand All @@ -104,8 +98,8 @@ static void openConnection(Machine::ptr machine, Path tmpDir, int stderrFD, Chil
to.readSide = -1;
from.writeSide = -1;

child.to = to.writeSide.release();
child.from = from.readSide.release();
child.in = to.writeSide.release();
child.out = from.readSide.release();
}


Expand Down Expand Up @@ -488,13 +482,13 @@ void State::buildRemote(ref<Store> destStore,
updateStep(ssConnecting);

// FIXME: rewrite to use Store.
Child child;
SSHMaster::Connection child;
build_remote::openConnection(machine, tmpDir, logFD.get(), child);

{
auto activeStepState(activeStep->state_.lock());
if (activeStepState->cancelled) throw Error("step cancelled");
activeStepState->pid = child.pid;
activeStepState->pid = child.sshPid;
}

Finally clearPid([&]() {
Expand All @@ -510,8 +504,8 @@ void State::buildRemote(ref<Store> destStore,
});

Machine::Connection conn {
.from = child.from.get(),
.to = child.to.get(),
.from = child.out.get(),
.to = child.in.get(),
.machine = machine,
};

Expand All @@ -523,7 +517,7 @@ void State::buildRemote(ref<Store> destStore,
try {
build_remote::handshake(conn, buildOptions.repeats);
} catch (EndOfFile & e) {
child.pid.wait();
child.sshPid.wait();
std::string s = chomp(readFile(result.logFile));
throw Error("cannot connect to ‘%1%’: %2%", machine->sshName, s);
}
Expand Down Expand Up @@ -617,8 +611,8 @@ void State::buildRemote(ref<Store> destStore,
}

/* Shut down the connection. */
child.to = -1;
child.pid.wait();
child.in = -1;
child.sshPid.wait();

} catch (Error & e) {
/* Disable this machine until a certain period of time has
Expand Down

0 comments on commit f5c0efb

Please sign in to comment.