diff options
author | Jesse Luehrs <doy@tozt.net> | 2023-08-06 19:52:32 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2023-08-06 19:52:32 -0400 |
commit | e725e77d5df5bb1273800237451eaa4f4ae92773 (patch) | |
tree | ccb246a29980b6d4c82f1c4f62fd1e7aa9b792b5 /tests | |
parent | 847bcb26c5a55196de92be7319dc6d8d5ca676f0 (diff) | |
download | pty-process-e725e77d5df5bb1273800237451eaa4f4ae92773.tar.gz pty-process-e725e77d5df5bb1273800237451eaa4f4ae92773.zip |
this cloexec was actually important
Diffstat (limited to 'tests')
-rw-r--r-- | tests/pipe.rs | 13 |
1 files changed, 13 insertions, 0 deletions
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(); +} |