From efd1536eb763e39a467469f530b91146bec707d9 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 25 Apr 2019 10:50:15 +0000 Subject: [PATCH] add a wrapper around nix::unistd::pipe2 Using O_CLOEXEC by default, and returning Fd handles to ensure they get dropped on bail!() or panic!() if the RawFds aren't used yet. Signed-off-by: Wolfgang Bumiller --- src/tools.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tools.rs b/src/tools.rs index 4da9c491..43a9bfe8 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -677,3 +677,9 @@ impl FromRawFd for Fd { Self(fd) } } + +// wrap nix::unistd::pipe2 + O_CLOEXEC into something returning guarded file descriptors +pub fn pipe() -> Result<(Fd, Fd), Error> { + let (pin, pout) = nix::unistd::pipe2(nix::fcntl::OFlag::O_CLOEXEC)?; + Ok((Fd(pin), Fd(pout))) +}