From 0f0718422ffec1d33f077e42487817f30fc5b873 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Fri, 4 Jul 2025 13:25:47 +0200 Subject: [PATCH] libutil: rename runProgram redirections to make more sense the `from`/`to` naming only made sense for unidirectional output fds, for others (and for the dup2 api in general) it was backwards. rename them to `dup`/`from` to make this look more like the assignment it is Change-Id: Iee50d06f9cfcea765ace6cfbe85b192829207e5f --- lix/libfetchers/git.cc | 4 ++-- lix/libstore/build/derivation-goal.cc | 2 +- lix/libstore/globals.cc | 2 +- lix/libstore/platform/linux.cc | 14 +++++++------- lix/libutil/processes.cc | 4 ++-- lix/libutil/processes.hh | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lix/libfetchers/git.cc b/lix/libfetchers/git.cc index aa3ef7150..118619c23 100644 --- a/lix/libfetchers/git.cc +++ b/lix/libfetchers/git.cc @@ -177,7 +177,7 @@ WorkdirInfo getWorkdirInfo(const Input & input, const Path & workdir) "--no-revs", "HEAD^{commit}"}, .environment = env, - .redirections = {{.from = STDERR_FILENO, .to = STDOUT_FILENO}}, + .redirections = {{.dup = STDERR_FILENO, .from = STDOUT_FILENO}}, }); auto exitCode = WEXITSTATUS(result.first); auto errorMessage = result.second; @@ -723,7 +723,7 @@ struct GitInputScheme : InputScheme .args = {"-C", repoDir, "--git-dir", gitDir, "cat-file", "commit", input.getRev()->gitRev() }, - .redirections = {{.from = STDERR_FILENO, .to = STDOUT_FILENO}}, + .redirections = {{.dup = STDERR_FILENO, .from = STDOUT_FILENO}}, }); if (WEXITSTATUS(result.first) == 128 && result.second.find("bad file") != std::string::npos) diff --git a/lix/libstore/build/derivation-goal.cc b/lix/libstore/build/derivation-goal.cc index a7edba697..7f29e30bf 100644 --- a/lix/libstore/build/derivation-goal.cc +++ b/lix/libstore/build/derivation-goal.cc @@ -892,7 +892,7 @@ void runPostBuildHook( .program = settings.postBuildHook, .environment = hookEnvironment, .captureStdout = true, - .redirections = {{.from = STDERR_FILENO, .to = STDOUT_FILENO}}, + .redirections = {{.dup = STDERR_FILENO, .from = STDOUT_FILENO}}, }); Finally const _wait([&] { try { diff --git a/lix/libstore/globals.cc b/lix/libstore/globals.cc index 7fc4c6a21..75f68e670 100644 --- a/lix/libstore/globals.cc +++ b/lix/libstore/globals.cc @@ -249,7 +249,7 @@ StringSet Settings::getDefaultExtraPlatforms() && runProgram(RunOptions{ .program = "arch", .args = {"-arch", "x86_64", "/usr/bin/true"}, - .redirections = {{.from = STDERR_FILENO, .to = STDOUT_FILENO}} + .redirections = {{.dup = STDERR_FILENO, .from = STDOUT_FILENO}} } ).first == 0) diff --git a/lix/libstore/platform/linux.cc b/lix/libstore/platform/linux.cc index 722135081..4e803d943 100644 --- a/lix/libstore/platform/linux.cc +++ b/lix/libstore/platform/linux.cc @@ -1100,13 +1100,13 @@ Pid LinuxLocalDerivationGoal::startChild(std::function openSlave) // descriptors very early and lacks fd arguments for the namespaces we // want it to join. we cannot have pasta join the namespaces via pids; // doing so requires capabilities which pasta *also* drops very early. - .redirections = { - {.from = 0, .to = netns.get()}, - {.from = 1, .to = userns ? userns.get() : 1}, - }, - .caps = getuid() == 0 - ? std::set{CAP_SYS_ADMIN, CAP_NET_BIND_SERVICE} - : std::set{}, + .redirections = + { + {.dup = 0, .from = netns.get()}, + {.dup = 1, .from = userns ? userns.get() : 1}, + }, + .caps = getuid() == 0 ? std::set{CAP_SYS_ADMIN, CAP_NET_BIND_SERVICE} + : std::set{}, }); } diff --git a/lix/libutil/processes.cc b/lix/libutil/processes.cc index 2f214e552..f8971f8bf 100644 --- a/lix/libutil/processes.cc +++ b/lix/libutil/processes.cc @@ -332,8 +332,8 @@ RunningProgram runProgram2(const RunOptions & options) if (options.captureStdout && dup2(out.writeSide.get(), STDOUT_FILENO) == -1) throw SysError("dupping stdout"); for (auto redirection : options.redirections) { - if (dup2(redirection.to, redirection.from) == -1) { - throw SysError("dupping fd %i to %i", redirection.from, redirection.to); + if (dup2(redirection.from, redirection.dup) == -1) { + throw SysError("dupping fd %i to %i", redirection.dup, redirection.from); } } diff --git a/lix/libutil/processes.hh b/lix/libutil/processes.hh index 6ca7f3bdf..8d9fe5c29 100644 --- a/lix/libutil/processes.hh +++ b/lix/libutil/processes.hh @@ -78,7 +78,7 @@ struct RunOptions { struct Redirection { - int from, to; + int dup, from; }; Path program;