aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/build/hook-instance.cc
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-04-05 21:02:04 +0200
committereldritch horrors <pennae@lix.systems>2024-06-23 11:52:49 +0000
commit3d155fc509e19354ba3798b1cc1b9cbcdb789c85 (patch)
treedc3dd72cd77e02e1aeb25d75c6e01bdf34041b28 /src/libstore/build/hook-instance.cc
parentb43a2e84c4b2fa7cb1167693652702e6dac95f53 (diff)
libutil: give Pid proper resource semantics
copy-constructing or assigning from pid_t can easily lead to duplicate Pid instances for the same process if a pid_t was used carelessly, and Pid itself was copy-constructible. both could cause surprising results such as killing processes twice (which could become very problemantic, but luckily modern systems don't reuse PIDs all that quickly), or more than one piece of the code believing it owns a process when neither do Change-Id: Ifea7445f84200b34c1a1d0acc2cdffe0f01e20c6
Diffstat (limited to 'src/libstore/build/hook-instance.cc')
-rw-r--r--src/libstore/build/hook-instance.cc4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libstore/build/hook-instance.cc b/src/libstore/build/hook-instance.cc
index 9a93646f4..b8d8fe7a4 100644
--- a/src/libstore/build/hook-instance.cc
+++ b/src/libstore/build/hook-instance.cc
@@ -35,7 +35,7 @@ HookInstance::HookInstance()
builderOut.create();
/* Fork the hook. */
- pid = startProcess([&]() {
+ pid = Pid{startProcess([&]() {
if (dup2(fromHook.writeSide.get(), STDERR_FILENO) == -1)
throw SysError("cannot pipe standard error into log file");
@@ -60,7 +60,7 @@ HookInstance::HookInstance()
execv(buildHook.c_str(), stringsToCharPtrs(args).data());
throw SysError("executing '%s'", buildHook);
- });
+ })};
pid.setSeparatePG(true);
fromHook.writeSide.reset();