@@ -2333,6 +2333,21 @@ impl IntParser { |
2333 | 2333 | mod subprocess_raw_fd_tests { |
2334 | 2334 | use super::*; |
2335 | 2335 |
|
| 2336 | + fn pipe_above_stdio() -> (OwnedFd, OwnedFd) { |
| 2337 | + let duplicate = |fd: OwnedFd, minimum| { |
| 2338 | + let raw = |
| 2339 | + nix::fcntl::fcntl(&fd, nix::fcntl::FcntlArg::F_DUPFD_CLOEXEC(minimum)).unwrap(); |
| 2340 | + // SAFETY: F_DUPFD_CLOEXEC returned a fresh descriptor owned by this test. |
| 2341 | + unsafe { OwnedFd::from_raw_fd(raw) } |
| 2342 | + }; |
| 2343 | + let (reader, writer) = nix::unistd::pipe().unwrap(); |
| 2344 | + // pipe() orders endpoints by direction, not descriptor number. Allocate |
| 2345 | + // the fixture above stderr and in the order required by the keep list. |
| 2346 | + let reader = duplicate(reader, 3); |
| 2347 | + let writer = duplicate(writer, reader.as_raw_fd() + 1); |
| 2348 | + (reader, writer) |
| 2349 | + } |
| 2350 | + |
2336 | 2351 | #[test] |
2337 | 2352 | fn invalid_raw_descriptors_return_ebadf() { |
2338 | 2353 | for err in [ |
@@ -2353,7 +2368,7 @@ mod subprocess_raw_fd_tests { |
2353 | 2368 |
|
2354 | 2369 | #[test] |
2355 | 2370 | fn raw_and_borrowed_keep_lists_select_the_same_descriptors() { |
2356 | | - let (reader, writer) = nix::unistd::pipe().unwrap(); |
| 2371 | + let (reader, writer) = pipe_above_stdio(); |
2357 | 2372 | let raw = [reader.as_raw_fd(), writer.as_raw_fd()]; |
2358 | 2373 | assert!(raw[0] > 2 && raw[1] > raw[0]); |
2359 | 2374 | let borrowed = [reader.as_fd(), writer.as_fd()]; |
@@ -2369,7 +2384,7 @@ mod subprocess_raw_fd_tests { |
2369 | 2384 |
|
2370 | 2385 | #[test] |
2371 | 2386 | fn raw_helpers_preserve_pipe_ownership_and_flags() { |
2372 | | - let (reader, writer) = nix::unistd::pipe().unwrap(); |
| 2387 | + let (reader, writer) = pipe_above_stdio(); |
2373 | 2388 | assert!(reader.as_raw_fd() > 2 && writer.as_raw_fd() > 2); |
2374 | 2389 | let high = nix::fcntl::fcntl(&writer, nix::fcntl::FcntlArg::F_DUPFD_CLOEXEC(64)).unwrap(); |
2375 | 2390 | // SAFETY: F_DUPFD_CLOEXEC returned a fresh descriptor owned by this test. |
|