From 50c35fc057be67eca70c42e3892aca8b9984b86b Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 2 Apr 2021 15:58:30 +0100 Subject: [PATCH] apitest: Move OtterPaused from wdt-simple Signed-off-by: Ian Jackson --- apitest/apitest.rs | 30 +++++++++++++++++++++++++++++- wdriver/wdt-simple.rs | 5 ++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/apitest/apitest.rs b/apitest/apitest.rs index 3c03dd43..58305f72 100644 --- a/apitest/apitest.rs +++ b/apitest/apitest.rs @@ -68,7 +68,7 @@ pub struct Opts { pub struct SetupCore { pub ds: DirSubst, pub mgmt_conn: MgmtChannel, - pub server_child: Child, + server_child: Child, pub wanted_tests: TrackWantedTests, } @@ -763,6 +763,34 @@ impl DirSubst { } } +// -------------------- concurrency management -------------------- + +pub struct OtterPaused(nix::unistd::Pid); + +impl SetupCore { + #[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) + } +} + +impl OtterPaused { + #[throws(AE)] + pub fn resume(self) { + nix::sys::signal::kill(self.0, nix::sys::signal::SIGCONT)?; + } +} + +impl Drop for OtterPaused { + fn drop(&mut self) { + debug!("note, otter server pid={} was still paused", self.0); + } +} + // -------------------- utilities -------------------- #[ext(pub)] diff --git a/wdriver/wdt-simple.rs b/wdriver/wdt-simple.rs index 4fc17769..35e37c5a 100644 --- a/wdriver/wdt-simple.rs +++ b/wdriver/wdt-simple.rs @@ -204,8 +204,7 @@ impl Ctx { dbg!(&sides); - let pid = nix::unistd::Pid::from_raw(su.server_child.id() as nix::libc::pid_t); - nix::sys::signal::kill(pid, nix::sys::signal::SIGSTOP)?; + let paused = su.pause_otter()?; for side in &sides { let w = su.w(side.window)?; @@ -223,7 +222,7 @@ impl Ctx { .context("conflicting drag")?; } - nix::sys::signal::kill(pid, nix::sys::signal::SIGCONT)?; + paused.resume()?; #[derive(Debug)] struct Got<'s> { -- 2.30.2