aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/ssh.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/ssh.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/ssh.cc')
-rw-r--r--src/libstore/ssh.cc8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/libstore/ssh.cc b/src/libstore/ssh.cc
index 0d7bfa01d..c40eba894 100644
--- a/src/libstore/ssh.cc
+++ b/src/libstore/ssh.cc
@@ -70,7 +70,7 @@ std::unique_ptr<SSHMaster::Connection> SSHMaster::startCommand(const std::string
}
Finally cleanup = [&]() { logger->resume(); };
- conn->sshPid = startProcess([&]() {
+ conn->sshPid = Pid{startProcess([&]() {
restoreProcessContext();
close(in.writeSide.get());
@@ -99,7 +99,7 @@ std::unique_ptr<SSHMaster::Connection> SSHMaster::startCommand(const std::string
// could not exec ssh/bash
throw SysError("unable to execute '%s'", args.front());
- }, options);
+ }, options)};
in.readSide.reset();
@@ -147,7 +147,7 @@ Path SSHMaster::startMaster()
if (isMasterRunning())
return state->socketPath;
- state->sshMaster = startProcess([&]() {
+ state->sshMaster = Pid{startProcess([&]() {
restoreProcessContext();
close(out.readSide.get());
@@ -160,7 +160,7 @@ Path SSHMaster::startMaster()
execvp(args.begin()->c_str(), stringsToCharPtrs(args).data());
throw SysError("unable to execute '%s'", args.front());
- }, options);
+ }, options)};
out.writeSide.reset();