Add test asserting stdlib uses O_CLOEXEC

This commit is contained in:
Mahmoud Al-Qudsi 2024-03-09 22:05:23 -06:00
parent d5cde80447
commit 4e95a3713e
2 changed files with 17 additions and 0 deletions

View file

@ -18,6 +18,7 @@ mod parser;
mod reader;
mod redirection;
mod screen;
mod std;
mod string_escape;
mod threads;
mod tokenizer;

16
src/tests/std.rs Normal file
View file

@ -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");
}