From 4e95a3713e77e56ee987894fd9daeaf52ceb9e02 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sat, 9 Mar 2024 22:05:23 -0600 Subject: [PATCH] Add test asserting stdlib uses O_CLOEXEC --- src/tests/mod.rs | 1 + src/tests/std.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/tests/std.rs diff --git a/src/tests/mod.rs b/src/tests/mod.rs index a5c28822b..61c68ab55 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -18,6 +18,7 @@ mod parser; mod reader; mod redirection; mod screen; +mod std; mod string_escape; mod threads; mod tokenizer; diff --git a/src/tests/std.rs b/src/tests/std.rs new file mode 100644 index 000000000..def07d1c8 --- /dev/null +++ b/src/tests/std.rs @@ -0,0 +1,16 @@ +//! This module contains tests that assert the functionality and behavior of the rust standard +//! library, to ensure we can safely use its abstractions to perform low-level operations. + +use std::fs::File; +use std::os::fd::AsRawFd; + +#[test] +fn test_fd_cloexec() { + // Just open a file. Any file. + let file = File::create("test_file_for_fd_cloexec").unwrap(); + let fd = file.as_raw_fd(); + unsafe { + assert_eq!(libc::fcntl(fd, libc::F_GETFD) & libc::FD_CLOEXEC, libc::FD_CLOEXEC); + } + let _ = std::fs::remove_file("test_file_for_fd_cloexec"); +}