From f201365cc42088068044e5b5b7dea1a3d9320039 Mon Sep 17 00:00:00 2001 From: edef Date: Sun, 31 Jul 2022 01:02:38 +0000 Subject: ripple/minitrace: terminate Process on drop This ensures even outright panics in minitrace still cleanly terminate the process. Change-Id: I5debbae2e6e1bb38ef8782bbdf9f26661876fdbe --- ripple/minitrace/src/main.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ripple/minitrace/src/main.rs b/ripple/minitrace/src/main.rs index 2d21f8b..34c503c 100644 --- a/ripple/minitrace/src/main.rs +++ b/ripple/minitrace/src/main.rs @@ -62,6 +62,14 @@ struct Process { pidfd: PidFd, } +impl Drop for Process { + fn drop(&mut self) { + if let Err(err) = self.terminate() { + eprintln!("{err}"); + } + } +} + impl Process { fn spawn(cmd: &mut Command) -> Result { unsafe { @@ -248,14 +256,10 @@ fn main() -> Result<()> { let regs = ptrace::getregs(event_tid.as_pid())?; let entry = match SyscallEntry::from_regs(&process, regs) { Ok(entry) => entry, - Err(err) => { - process.terminate()?; - panic!("{err}"); - } + Err(err) => panic!("{err}"), }; if !check_syscall(&entry) { - process.terminate()?; panic!("invalid syscall {entry:?}"); } -- cgit 1.4.1