From a053ef8fdf76cfde41fc8232c8e129454c68378e Mon Sep 17 00:00:00 2001 From: leo60228 Date: Fri, 10 May 2024 15:00:54 -0400 Subject: [PATCH] lix api changes --- src/hydra-eval-jobs/hydra-eval-jobs.cc | 14 +++++++------- src/hydra-evaluator/hydra-evaluator.cc | 6 +++++- src/hydra-queue-runner/build-remote.cc | 14 +++++++------- src/hydra-queue-runner/hydra-queue-runner.cc | 16 +--------------- src/hydra-queue-runner/queue-monitor.cc | 2 +- src/libhydra/db.hh | 2 +- 6 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/hydra-eval-jobs/hydra-eval-jobs.cc b/src/hydra-eval-jobs/hydra-eval-jobs.cc index 9cc1d50c..0246efd5 100644 --- a/src/hydra-eval-jobs/hydra-eval-jobs.cc +++ b/src/hydra-eval-jobs/hydra-eval-jobs.cc @@ -8,6 +8,7 @@ #include "eval.hh" #include "eval-inline.hh" #include "eval-settings.hh" +#include "signals.hh" #include "util.hh" #include "get-drvs.hh" #include "globals.hh" @@ -160,7 +161,7 @@ static void worker( auto s = readLine(from.get()); if (s == "exit") break; - if (!hasPrefix(s, "do ")) abort(); + if (!s.starts_with("do ")) abort(); std::string attrPath(s, 3); debug("worker process %d at '%s'", getpid(), attrPath); @@ -183,7 +184,7 @@ static void worker( !experimentalFeatureSettings.isEnabled(Xp::CaDerivations)); if (drv->querySystem() == "unknown") - throw EvalError("derivation must have a 'system' attribute"); + state.error("derivation must have a 'system' attribute").debugThrow(); auto drvPath = state.store->printStorePath(drv->requireDrvPath()); @@ -206,7 +207,7 @@ static void worker( if (a && state.forceBool(*a->value, a->pos, "while evaluating the `_hydraAggregate` attribute")) { auto a = v->attrs->get(state.symbols.create("constituents")); if (!a) - throw EvalError("derivation must have a ‘constituents’ attribute"); + state.error("derivation must have a ‘constituents’ attribute").debugThrow(); NixStringContext context; state.coerceToString(a->pos, *a->value, context, "while evaluating the `constituents` attribute", true, false); @@ -272,7 +273,7 @@ static void worker( else if (v->type() == nNull) ; - else throw TypeError("attribute '%s' is %s, which is not supported", attrPath, showType(*v)); + else state.error("attribute '%s' is %s, which is not supported", attrPath, showType(*v)).debugThrow(); } catch (EvalError & e) { auto msg = e.msg(); @@ -379,8 +380,7 @@ int main(int argc, char * * argv) // what's shown in the Hydra UI. writeLine(to->get(), "restart"); } - }, - ProcessOptions { .allowVfork = false }); + }); from = std::move(fromPipe.readSide); to = std::move(toPipe.writeSide); debug("created worker process %d", pid); @@ -531,7 +531,7 @@ int main(int argc, char * * argv) if (brokenJobs.empty()) { std::string drvName(drvPath.name()); - assert(hasSuffix(drvName, drvExtension)); + assert(drvName.ends_with(drvExtension)); drvName.resize(drvName.size() - drvExtension.size()); auto hashModulo = hashDerivationModulo(*store, drv, true); diff --git a/src/hydra-evaluator/hydra-evaluator.cc b/src/hydra-evaluator/hydra-evaluator.cc index a1ccf047..d99a826b 100644 --- a/src/hydra-evaluator/hydra-evaluator.cc +++ b/src/hydra-evaluator/hydra-evaluator.cc @@ -2,6 +2,7 @@ #include "hydra-config.hh" #include "pool.hh" #include "shared.hh" +#include "signals.hh" #include #include @@ -11,7 +12,10 @@ #include #include +#include + using namespace nix; +using boost::format; typedef std::pair JobsetName; @@ -505,7 +509,7 @@ int main(int argc, char * * argv) parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) { if (*arg == "--unlock") unlock = true; - else if (hasPrefix(*arg, "-")) + else if (arg->starts_with("-")) return false; args.push_back(*arg); return true; diff --git a/src/hydra-queue-runner/build-remote.cc b/src/hydra-queue-runner/build-remote.cc index f9e61df5..459beed9 100644 --- a/src/hydra-queue-runner/build-remote.cc +++ b/src/hydra-queue-runner/build-remote.cc @@ -93,11 +93,11 @@ static void openConnection(::Machine::ptr machine, Path tmpDir, int stderrFD, SS throw SysError("cannot start %s", pgmName); }); - to.readSide = -1; - from.writeSide = -1; + to.readSide.reset(); + from.writeSide.reset(); - child.in = to.writeSide.release(); - child.out = from.readSide.release(); + child.in = AutoCloseFD{to.writeSide.release()}; + child.out = AutoCloseFD{from.readSide.release()}; // XXX: determine the actual max value we can use from /proc. int pipesize = 1024 * 1024; @@ -186,7 +186,7 @@ static std::pair openLogFile(const std::string & logDir, cons createDirs(dirOf(logFile)); - AutoCloseFD logFD = open(logFile.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0666); + AutoCloseFD logFD{open(logFile.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0666)}; if (!logFD) throw SysError("creating log file ‘%s’", logFile); return {std::move(logFile), std::move(logFD)}; @@ -588,7 +588,7 @@ void State::buildRemote(ref destStore, if (ftruncate(logFD.get(), 0) == -1) throw SysError("truncating log file ‘%s’", result.logFile); - logFD = -1; + logFD.reset(); /* Do the build. */ printMsg(lvlDebug, "building ‘%s’ on ‘%s’", @@ -684,7 +684,7 @@ void State::buildRemote(ref destStore, } /* Shut down the connection. */ - child.in = -1; + child.in.reset(); child.sshPid.wait(); } catch (Error & e) { diff --git a/src/hydra-queue-runner/hydra-queue-runner.cc b/src/hydra-queue-runner/hydra-queue-runner.cc index 5f288dc7..5b679d18 100644 --- a/src/hydra-queue-runner/hydra-queue-runner.cc +++ b/src/hydra-queue-runner/hydra-queue-runner.cc @@ -11,10 +11,10 @@ #include +#include "signals.hh" #include "state.hh" #include "hydra-build-result.hh" #include "store-api.hh" -#include "remote-store.hh" #include "globals.hh" #include "hydra-config.hh" @@ -930,20 +930,6 @@ void State::run(BuildID buildOne) } }).detach(); - /* Make sure that old daemon connections are closed even when - we're not doing much. */ - std::thread([&]() { - while (true) { - sleep(10); - try { - if (auto remoteStore = getDestStore().dynamic_pointer_cast()) - remoteStore->flushBadConnections(); - } catch (std::exception & e) { - printMsg(lvlError, "connection flush thread: %s", e.what()); - } - } - }).detach(); - /* Monitor the database for status dump requests (e.g. from ‘hydra-queue-runner --status’). */ while (true) { diff --git a/src/hydra-queue-runner/queue-monitor.cc b/src/hydra-queue-runner/queue-monitor.cc index 4202bb6d..a40cff17 100644 --- a/src/hydra-queue-runner/queue-monitor.cc +++ b/src/hydra-queue-runner/queue-monitor.cc @@ -299,7 +299,7 @@ bool State::getQueuedBuilds(Connection & conn, try { createBuild(build); } catch (Error & e) { - e.addTrace({}, hintfmt("while loading build %d: ", build->id)); + e.addTrace({}, HintFmt("while loading build %d: ", build->id)); throw; } diff --git a/src/libhydra/db.hh b/src/libhydra/db.hh index 00e8f406..7e28c3a7 100644 --- a/src/libhydra/db.hh +++ b/src/libhydra/db.hh @@ -17,7 +17,7 @@ struct Connection : pqxx::connection std::string lower_prefix = "dbi:Pg:"; std::string upper_prefix = "DBI:Pg:"; - if (hasPrefix(s, lower_prefix) || hasPrefix(s, upper_prefix)) { + if (s.starts_with(lower_prefix) || s.starts_with(upper_prefix)) { return concatStringsSep(" ", tokenizeString(std::string(s, lower_prefix.size()), ";")); }