Skip to content

Commit 4e95a37

Browse files
committed
Add test asserting stdlib uses O_CLOEXEC
1 parent d5cde80 commit 4e95a37

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ mod parser;
1818
mod reader;
1919
mod redirection;
2020
mod screen;
21+
mod std;
2122
mod string_escape;
2223
mod threads;
2324
mod tokenizer;

src/tests/std.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//! This module contains tests that assert the functionality and behavior of the rust standard
2+
//! library, to ensure we can safely use its abstractions to perform low-level operations.
3+
4+
use std::fs::File;
5+
use std::os::fd::AsRawFd;
6+
7+
#[test]
8+
fn test_fd_cloexec() {
9+
// Just open a file. Any file.
10+
let file = File::create("test_file_for_fd_cloexec").unwrap();
11+
let fd = file.as_raw_fd();
12+
unsafe {
13+
assert_eq!(libc::fcntl(fd, libc::F_GETFD) & libc::FD_CLOEXEC, libc::FD_CLOEXEC);
14+
}
15+
let _ = std::fs::remove_file("test_file_for_fd_cloexec");
16+
}

0 commit comments

Comments
 (0)