chiark / gitweb /
apitest: Provide OtterPauseable etc.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 2 Apr 2021 15:10:47 +0000 (16:10 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 2 Apr 2021 15:10:47 +0000 (16:10 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
apitest/apitest.rs

index 58305f72a5ae10a9a689da09730db14df68a8402..211ef5b50e6b23e99e182b249168344b02f409c4 100644 (file)
@@ -765,23 +765,35 @@ impl DirSubst {
 
 // -------------------- concurrency management --------------------
 
+pub struct OtterPauseable(nix::unistd::Pid);
 pub struct OtterPaused(nix::unistd::Pid);
 
 impl SetupCore {
+  pub fn otter_pauseable(&self) -> OtterPauseable {
+    OtterPauseable(nix::unistd::Pid::from_raw(
+      self.server_child.id() as nix::libc::pid_t
+    ))
+  }
+
   #[throws(AE)]
   pub fn pause_otter(&self) -> OtterPaused {
-    let pid = nix::unistd::Pid::from_raw(
-      self.server_child.id() as nix::libc::pid_t
-    );
-    nix::sys::signal::kill(pid, nix::sys::signal::SIGSTOP)?;
-    OtterPaused(pid)
+    self.otter_pauseable().pause()?
+  }
+}
+
+impl OtterPauseable {
+  #[throws(AE)]
+  pub fn pause(self) -> OtterPaused {
+    nix::sys::signal::kill(self.0, nix::sys::signal::SIGSTOP)?;
+    OtterPaused(self.0)
   }
 }
 
 impl OtterPaused {
   #[throws(AE)]
-  pub fn resume(self) {
+  pub fn resume(self) -> OtterPauseable {
     nix::sys::signal::kill(self.0, nix::sys::signal::SIGCONT)?;
+    OtterPauseable(self.0)
   }
 }