From 4e8fbaa3d688a4ffa95ccbaa0af889569c918633 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 23 Jan 2024 00:00:23 -0500 Subject: [PATCH] Replace `Child` with `SSHMaster::Connection` Nix defines basically an identical struct for the same purpose, so let's just use that. --- src/hydra-queue-runner/build-remote.cc | 30 +++++++++++--------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/hydra-queue-runner/build-remote.cc b/src/hydra-queue-runner/build-remote.cc index b117fdad..a4f3a35c 100644 --- a/src/hydra-queue-runner/build-remote.cc +++ b/src/hydra-queue-runner/build-remote.cc @@ -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()); @@ -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; @@ -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) @@ -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(); } @@ -488,13 +482,13 @@ void State::buildRemote(ref 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([&]() { @@ -510,8 +504,8 @@ void State::buildRemote(ref destStore, }); Machine::Connection conn { - .from = child.from.get(), - .to = child.to.get(), + .from = child.out.get(), + .to = child.in.get(), .machine = machine, }; @@ -523,7 +517,7 @@ void State::buildRemote(ref 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); } @@ -617,8 +611,8 @@ void State::buildRemote(ref 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