]> git.proxmox.com Git - proxmox-backup.git/commitdiff
tools: pub use Fd from proxmox crate
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 24 Apr 2020 08:06:11 +0000 (10:06 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 24 Apr 2020 08:56:52 +0000 (10:56 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/tools.rs

index fa93796b660ff747c5b1f7367a2d27207cff11a9..873bc336d8546c5151f99186ef72d40bd84d787d 100644 (file)
@@ -7,7 +7,7 @@ use std::hash::BuildHasher;
 use std::fs::{File, OpenOptions};
 use std::io::ErrorKind;
 use std::io::Read;
-use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
+use std::os::unix::io::{AsRawFd, RawFd};
 use std::path::Path;
 use std::time::Duration;
 
@@ -18,6 +18,8 @@ use percent_encoding::AsciiSet;
 
 use proxmox::tools::vec;
 
+pub use proxmox::tools::fd::Fd;
+
 pub mod acl;
 pub mod async_io;
 pub mod borrow;
@@ -500,41 +502,6 @@ pub fn fail_on_shutdown() -> Result<(), Error> {
     Ok(())
 }
 
-/// Guard a raw file descriptor with a drop handler. This is mostly useful when access to an owned
-/// `RawFd` is required without the corresponding handler object (such as when only the file
-/// descriptor number is required in a closure which may be dropped instead of being executed).
-pub struct Fd(pub RawFd);
-
-impl Drop for Fd {
-    fn drop(&mut self) {
-        if self.0 != -1 {
-            unsafe {
-                libc::close(self.0);
-            }
-        }
-    }
-}
-
-impl AsRawFd for Fd {
-    fn as_raw_fd(&self) -> RawFd {
-        self.0
-    }
-}
-
-impl IntoRawFd for Fd {
-    fn into_raw_fd(mut self) -> RawFd {
-        let fd = self.0;
-        self.0 = -1;
-        fd
-    }
-}
-
-impl FromRawFd for Fd {
-    unsafe fn from_raw_fd(fd: RawFd) -> Self {
-        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)?;