diff options
author | eldritch horrors <pennae@lix.systems> | 2024-08-13 15:34:55 +0200 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-08-19 09:13:44 +0000 |
commit | 5e9db0976158e6990c99fe3cb1b2ec0bd41d7d28 (patch) | |
tree | 56ffcd005d88c6ea54517ae2f4862621bc855308 /src/libstore/build/hook-instance.cc | |
parent | e513cd2bebe6c4ed012bd4d2e92650c67f0df4bf (diff) |
libstore: downsize hook pipes
don't keep fds open we're not using. currently this does not cause any
problems, but it does increase the size of our fd table needlessly and
in the future, when we have proper async processing, having builderOut
open in the daemon once the hook has been fully started is problematic
Change-Id: I6e7fb773b280b042873103638d3e04272ca1e4fc
Diffstat (limited to 'src/libstore/build/hook-instance.cc')
-rw-r--r-- | src/libstore/build/hook-instance.cc | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/libstore/build/hook-instance.cc b/src/libstore/build/hook-instance.cc index 9a93646f4..d5da80c74 100644 --- a/src/libstore/build/hook-instance.cc +++ b/src/libstore/build/hook-instance.cc @@ -26,18 +26,21 @@ HookInstance::HookInstance() args.push_back(std::to_string(verbosity)); /* Create a pipe to get the output of the child. */ - fromHook.create(); + Pipe fromHook_; + fromHook_.create(); /* Create the communication pipes. */ - toHook.create(); + Pipe toHook_; + toHook_.create(); /* Create a pipe to get the output of the builder. */ - builderOut.create(); + Pipe builderOut_; + builderOut_.create(); /* Fork the hook. */ pid = startProcess([&]() { - if (dup2(fromHook.writeSide.get(), STDERR_FILENO) == -1) + if (dup2(fromHook_.writeSide.get(), STDERR_FILENO) == -1) throw SysError("cannot pipe standard error into log file"); commonChildInit(); @@ -45,16 +48,16 @@ HookInstance::HookInstance() if (chdir("/") == -1) throw SysError("changing into /"); /* Dup the communication pipes. */ - if (dup2(toHook.readSide.get(), STDIN_FILENO) == -1) + if (dup2(toHook_.readSide.get(), STDIN_FILENO) == -1) throw SysError("dupping to-hook read side"); /* Use fd 4 for the builder's stdout/stderr. */ - if (dup2(builderOut.writeSide.get(), 4) == -1) + if (dup2(builderOut_.writeSide.get(), 4) == -1) throw SysError("dupping builder's stdout/stderr"); /* Hack: pass the read side of that fd to allow build-remote to read SSH error messages. */ - if (dup2(builderOut.readSide.get(), 5) == -1) + if (dup2(builderOut_.readSide.get(), 5) == -1) throw SysError("dupping builder's stdout/stderr"); execv(buildHook.c_str(), stringsToCharPtrs(args).data()); @@ -63,10 +66,11 @@ HookInstance::HookInstance() }); pid.setSeparatePG(true); - fromHook.writeSide.reset(); - toHook.readSide.reset(); + fromHook = std::move(fromHook_.readSide); + toHook = std::move(toHook_.writeSide); + builderOut = std::move(builderOut_.readSide); - sink = FdSink(toHook.writeSide.get()); + sink = FdSink(toHook.get()); std::map<std::string, Config::SettingInfo> settings; globalConfig.getSettings(settings); for (auto & setting : settings) @@ -78,7 +82,7 @@ HookInstance::HookInstance() HookInstance::~HookInstance() { try { - toHook.writeSide.reset(); + toHook.reset(); if (pid) pid.kill(); } catch (...) { ignoreException(); |