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
This commit is contained in:
eldritch horrors
2025-07-04 14:01:08 +02:00
parent 897f87e76a
commit 0f0718422f
6 changed files with 14 additions and 14 deletions
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -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 {
+1 -1
View File
@@ -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)
+7 -7
View File
@@ -1100,13 +1100,13 @@ Pid LinuxLocalDerivationGoal::startChild(std::function<void()> 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<long>{CAP_SYS_ADMIN, CAP_NET_BIND_SERVICE}
: std::set<long>{},
.redirections =
{
{.dup = 0, .from = netns.get()},
{.dup = 1, .from = userns ? userns.get() : 1},
},
.caps = getuid() == 0 ? std::set<long>{CAP_SYS_ADMIN, CAP_NET_BIND_SERVICE}
: std::set<long>{},
});
}
+2 -2
View File
@@ -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);
}
}
+1 -1
View File
@@ -78,7 +78,7 @@ struct RunOptions
{
struct Redirection
{
int from, to;
int dup, from;
};
Path program;