summaryrefslogtreecommitdiffstats
path: root/library/std/src/sys/unix/process/process_unix/tests.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /library/std/src/sys/unix/process/process_unix/tests.rs
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/std/src/sys/unix/process/process_unix/tests.rs')
-rw-r--r--library/std/src/sys/unix/process/process_unix/tests.rs25
1 files changed, 25 insertions, 0 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 e5e1f956b..6aa79e7f9 100644
--- a/library/std/src/sys/unix/process/process_unix/tests.rs
+++ b/library/std/src/sys/unix/process/process_unix/tests.rs
@@ -60,3 +60,28 @@ fn test_command_fork_no_unwind() {
|| signal == libc::SIGSEGV
);
}
+
+#[test]
+#[cfg(target_os = "linux")]
+fn test_command_pidfd() {
+ use crate::os::fd::RawFd;
+ use crate::os::linux::process::{ChildExt, CommandExt};
+ use crate::process::Command;
+
+ let our_pid = crate::process::id();
+ let pidfd = unsafe { libc::syscall(libc::SYS_pidfd_open, our_pid, 0) };
+ let pidfd_open_available = if pidfd >= 0 {
+ unsafe { libc::close(pidfd as RawFd) };
+ true
+ } else {
+ false
+ };
+
+ // always exercise creation attempts
+ let child = Command::new("echo").create_pidfd(true).spawn().unwrap();
+
+ // but only check if we know that the kernel supports pidfds
+ if pidfd_open_available {
+ assert!(child.pidfd().is_ok())
+ }
+}