diff --git a/src/sys/ptrace/bsd.rs b/src/sys/ptrace/bsd.rs index fe07f55b8e..df8508a862 100644 --- a/src/sys/ptrace/bsd.rs +++ b/src/sys/ptrace/bsd.rs @@ -103,6 +103,14 @@ pub fn cont>>(pid: Pid, sig: T) -> Result<()> { } } +/// Issues a kill request as with ptrace(PT_KILL, ..-) +/// This request is equivalent to ptrace(PT_CONTINUE, ..., SIGKILL); +pub fn kill(pid: Pid) -> Result<()> { + unsafe { + ptrace_other(Request::PT_KILL, pid, 0 as AddressType, 0).map(|_| ()) + } +} + /// Move the stopped tracee process forward by a single step as with /// `ptrace(PT_STEP, ...)` /// diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs index 03ab1f1fe2..7d6dbfadac 100644 --- a/src/sys/ptrace/linux.rs +++ b/src/sys/ptrace/linux.rs @@ -320,6 +320,15 @@ pub fn cont>>(pid: Pid, sig: T) -> Result<()> { } } + +/// Issues a kill request as with ptrace(PTRACE_KILL, ..-) +/// This request is equivalent to ptrace(PTRACE_CONT, ..., SIGKILL); +pub fn kill(pid: Pid) -> Result<()> { + unsafe { + ptrace_other(Request::PTRACE_KILL, pid, ptr::null_mut(), ptr::null_mut()).map(|_| ()) + } +} + /// Move the stopped tracee process forward by a single step as with /// `ptrace(PTRACE_SINGLESTEP, ...)` /// diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs index ed62a88955..9608d0a240 100644 --- a/test/sys/test_ptrace.rs +++ b/test/sys/test_ptrace.rs @@ -55,7 +55,7 @@ fn test_ptrace_setsiginfo() { #[test] fn test_ptrace_cont() { use nix::sys::ptrace; - use nix::sys::signal::{kill, raise, Signal}; + use nix::sys::signal::{raise, Signal}; use nix::sys::wait::{waitpid, WaitStatus}; use nix::unistd::fork; use nix::unistd::ForkResult::*; @@ -87,14 +87,14 @@ fn test_ptrace_cont() { assert_eq!(waitpid(child, None), Ok(WaitStatus::Stopped(child, Signal::SIGTRAP))); ptrace::cont(child, None).unwrap(); assert_eq!(waitpid(child, None), Ok(WaitStatus::Stopped(child, Signal::SIGTRAP))); - ptrace::cont(child, Signal::SIGKILL).unwrap(); + ptrace::kill(child).unwrap(); match waitpid(child, None) { Ok(WaitStatus::Signaled(pid, Signal::SIGKILL, _)) if pid == child => { // Some systems require the tracee is in // signal-delivery-stop otherwise the signal is discarded // and the tracee doesn't actually get killed despite // receiving the signal - let _ = kill(child, None); + //let _ = kill(child, None); } _ => panic!("The process should have been killed"), }