diff options
author | Mika Vatanen <blaind@blaind.net> | 2021-04-11 10:39:46 +0300 |
---|---|---|
committer | Mika Vatanen <blaind@blaind.net> | 2021-08-09 20:29:44 +0300 |
commit | 1cbde2bb472507bdc6b84ec9ba6172dfcc2c01c5 (patch) | |
tree | ac2820918c5ff7b20f6d75d430cbefc21d9d5488 /test/sys | |
parent | 4c4be116f6414dbc9258f67102ea4b525efc037f (diff) | |
download | nix-1cbde2bb472507bdc6b84ec9ba6172dfcc2c01c5.zip |
Add PTRACE_INTERRUPT
Diffstat (limited to 'test/sys')
-rw-r--r-- | test/sys/test_ptrace.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs index 985945d1..ceb39b9b 100644 --- a/test/sys/test_ptrace.rs +++ b/test/sys/test_ptrace.rs @@ -114,6 +114,48 @@ fn test_ptrace_cont() { } } +#[cfg(target_os = "linux")] +#[test] +fn test_ptrace_interrupt() { + use nix::sys::ptrace; + use nix::sys::signal::Signal; + use nix::sys::wait::{waitpid, WaitPidFlag, WaitStatus}; + use nix::unistd::fork; + use nix::unistd::ForkResult::*; + use std::thread::sleep; + use std::time::Duration; + + require_capability!(CAP_SYS_PTRACE); + + let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test"); + + match unsafe{fork()}.expect("Error: Fork Failed") { + Child => { + loop { + sleep(Duration::from_millis(1000)); + } + + }, + Parent { child } => { + ptrace::seize(child, ptrace::Options::PTRACE_O_TRACESYSGOOD).unwrap(); + ptrace::interrupt(child).unwrap(); + assert_eq!(waitpid(child, None), Ok(WaitStatus::PtraceEvent(child, Signal::SIGTRAP, 128))); + ptrace::syscall(child, None).unwrap(); + assert_eq!(waitpid(child, None), Ok(WaitStatus::PtraceSyscall(child))); + ptrace::detach(child, Some(Signal::SIGKILL)).unwrap(); + match waitpid(child, None) { + Ok(WaitStatus::Signaled(pid, Signal::SIGKILL, _)) if pid == child => { + let _ = waitpid(child, Some(WaitPidFlag::WNOHANG)); + while ptrace::cont(child, Some(Signal::SIGKILL)).is_ok() { + let _ = waitpid(child, Some(WaitPidFlag::WNOHANG)); + } + } + _ => panic!("The process should have been killed"), + } + }, + } +} + // ptrace::{setoptions, getregs} are only available in these platforms #[cfg(all(target_os = "linux", any(target_arch = "x86_64", |