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