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 <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-04-25 10:50:15 +00:00
parent 897982e237
commit efd1536eb7

View File

@ -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)))
}