diff options
| author | The 8472 <git@infinite-source.de> | 2023-11-16 01:41:02 +0100 |
|---|---|---|
| committer | The 8472 <git@infinite-source.de> | 2023-11-16 02:05:37 +0100 |
| commit | 12efa53b19aad30747f566787853e773797edb26 (patch) | |
| tree | 9ee85b118460f882b2b40236b8cba832e331621f /library/std/src/sys/unix/process/process_unix | |
| parent | 3ffbb4899ec55b59b03325f25ff563530260b854 (diff) | |
if available use a Child's pidfd for kill/wait
Diffstat (limited to 'library/std/src/sys/unix/process/process_unix')
| -rw-r--r-- | library/std/src/sys/unix/process/process_unix/tests.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/library/std/src/sys/unix/process/process_unix/tests.rs b/library/std/src/sys/unix/process/process_unix/tests.rs index d237a7f6bf3..6e952ed7c42 100644 --- a/library/std/src/sys/unix/process/process_unix/tests.rs +++ b/library/std/src/sys/unix/process/process_unix/tests.rs @@ -64,6 +64,7 @@ fn test_command_fork_no_unwind() { #[test] #[cfg(target_os = "linux")] fn test_command_pidfd() { + use crate::assert_matches::assert_matches; use crate::os::fd::{AsRawFd, RawFd}; use crate::os::linux::process::{ChildExt, CommandExt}; use crate::process::Command; @@ -78,7 +79,7 @@ fn test_command_pidfd() { }; // always exercise creation attempts - let child = Command::new("echo").create_pidfd(true).spawn().unwrap(); + let mut child = Command::new("false").create_pidfd(true).spawn().unwrap(); // but only check if we know that the kernel supports pidfds if pidfd_open_available { @@ -88,4 +89,12 @@ fn test_command_pidfd() { let flags = super::cvt(unsafe { libc::fcntl(pidfd.as_raw_fd(), libc::F_GETFD) }).unwrap(); assert!(flags & libc::FD_CLOEXEC != 0); } + let status = child.wait().expect("error waiting on pidfd"); + assert_eq!(status.code(), Some(1)); + + let mut child = Command::new("sleep").arg("1000").create_pidfd(true).spawn().unwrap(); + assert_matches!(child.try_wait(), Ok(None)); + child.kill().expect("failed to kill child"); + let status = child.wait().expect("error waiting on pidfd"); + assert_eq!(status.signal(), Some(libc::SIGKILL)); } |
