summary refs log tree commit diff
path: root/ripple
diff options
context:
space:
mode:
authoredef <edef@unfathomable.blue>2022-07-31 00:57:43 +0000
committeredef <edef@unfathomable.blue>2022-07-31 00:57:43 +0000
commit39945afb70eb59ef348c512e8d3447027d13929c (patch)
tree9c118187dc993da285cf9e25366d9c3919d0159c /ripple
parent71d008beb8557eb30d09d4d4ce19f457957d578d (diff)
ripple/minitrace: use kill(2) over PTRACE_KILL
PTRACE_KILL is deprecated, and the manpage recommends using
kill(pid, SIGKILL) instead.

Change-Id: I8eda5a7add224838c2b01ef8b6999560bae446eb
Diffstat (limited to 'ripple')
-rw-r--r--ripple/minitrace/src/main.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/ripple/minitrace/src/main.rs b/ripple/minitrace/src/main.rs
index 9d577de..5bc6e23 100644
--- a/ripple/minitrace/src/main.rs
+++ b/ripple/minitrace/src/main.rs
@@ -12,7 +12,7 @@ use {
 			personality::{self, Persona},
 			ptrace,
 			resource::{self, Resource as HostResource},
-			signal::Signal as HostSignal,
+			signal::{kill, Signal as HostSignal},
 			wait::{waitpid, WaitPidFlag, WaitStatus},
 		},
 		unistd::Pid,
@@ -103,6 +103,13 @@ impl Process {
 		})
 	}
 
+	fn terminate(&self) -> Result<()> {
+		match kill(self.tgid.as_pid(), HostSignal::SIGKILL) {
+			Ok(()) | Err(nix::Error::ESRCH) => Ok(()),
+			Err(err) => Err(anyhow::Error::from(err).context("Couldn't terminate child")),
+		}
+	}
+
 	fn read_mem_cstr(&self, ptr: u64) -> Result<CString> {
 		let mut mem = io::BufReader::new(&self.mem);
 		mem.seek(SeekFrom::Start(ptr))?;
@@ -234,13 +241,13 @@ fn main() -> Result<()> {
 				let entry = match SyscallEntry::from_regs(&process, regs) {
 					Ok(entry) => entry,
 					Err(err) => {
-						ptrace::kill(event_tid.as_pid())?;
+						process.terminate()?;
 						panic!("{err}");
 					}
 				};
 
 				if !check_syscall(&entry) {
-					ptrace::kill(event_tid.as_pid())?;
+					process.terminate()?;
 					panic!("invalid syscall {entry:?}");
 				}