From e725e77d5df5bb1273800237451eaa4f4ae92773 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 6 Aug 2023 19:52:32 -0400 Subject: this cloexec was actually important --- tests/pipe.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/pipe.rs b/tests/pipe.rs index 1b77019..da2e1b0 100644 --- a/tests/pipe.rs +++ b/tests/pipe.rs @@ -96,7 +96,20 @@ fn pipe() -> (std::os::fd::OwnedFd, std::os::fd::OwnedFd) { use std::os::fd::FromRawFd as _; let (r, w) = nix::unistd::pipe().unwrap(); + cloexec(r); + cloexec(w); (unsafe { std::os::fd::OwnedFd::from_raw_fd(r) }, unsafe { std::os::fd::OwnedFd::from_raw_fd(w) }) } + +fn cloexec(fd: i32) { + let flags = nix::fcntl::fcntl(fd, nix::fcntl::FcntlArg::F_GETFD).unwrap(); + let mut flags = nix::fcntl::FdFlag::from_bits(flags).unwrap(); + flags |= nix::fcntl::FdFlag::FD_CLOEXEC; + nix::fcntl::fcntl( + fd, + nix::fcntl::FcntlArg::F_SETFD(nix::fcntl::FdFlag::FD_CLOEXEC), + ) + .unwrap(); +} -- cgit v1.2.3-54-g00ecf