From 80df41a887d2c9a8314c5833a4e93ed4b598a1bd Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 25 Nov 2021 10:34:33 +0100 Subject: [PATCH] proxmox-sys: import pipe() function from pbs-toos/src/io.rs Signed-off-by: Dietmar Maurer --- proxmox-sys/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/proxmox-sys/src/lib.rs b/proxmox-sys/src/lib.rs index dcbb1aca..c974fc58 100644 --- a/proxmox-sys/src/lib.rs +++ b/proxmox-sys/src/lib.rs @@ -24,6 +24,8 @@ macro_rules! identity { #[cfg(feature = "sortable-macro")] pub use proxmox_sortable_macro::sortable; +use fd::Fd; + /// Returns the hosts node name (UTS node name) pub fn nodename() -> &'static str { lazy_static::lazy_static! { @@ -39,3 +41,10 @@ pub fn nodename() -> &'static str { &NODENAME } + +/// Safe wrapper for `nix::unistd::pipe2` defaulting to `O_CLOEXEC` +/// and guarding the file descriptors. +pub fn pipe() -> Result<(Fd, Fd), nix::Error> { + let (pin, pout) = nix::unistd::pipe2(nix::fcntl::OFlag::O_CLOEXEC)?; + Ok((Fd(pin), Fd(pout))) +}