proxmox-sys: import pipe() function from pbs-toos/src/io.rs

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
Dietmar Maurer 2021-11-25 10:34:33 +01:00
parent d357ce2070
commit 80df41a887

View File

@ -24,6 +24,8 @@ macro_rules! identity {
#[cfg(feature = "sortable-macro")] #[cfg(feature = "sortable-macro")]
pub use proxmox_sortable_macro::sortable; pub use proxmox_sortable_macro::sortable;
use fd::Fd;
/// Returns the hosts node name (UTS node name) /// Returns the hosts node name (UTS node name)
pub fn nodename() -> &'static str { pub fn nodename() -> &'static str {
lazy_static::lazy_static! { lazy_static::lazy_static! {
@ -39,3 +41,10 @@ pub fn nodename() -> &'static str {
&NODENAME &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)))
}