forked from Proxmox/proxmox
sys: remove deprecations
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
3dde52e5ce
commit
c6cccff92e
@ -6,15 +6,6 @@ use nix::fcntl::OFlag;
|
|||||||
use nix::sys::stat::Mode;
|
use nix::sys::stat::Mode;
|
||||||
use nix::NixPath;
|
use nix::NixPath;
|
||||||
|
|
||||||
mod fd_impl;
|
|
||||||
pub use fd_impl::*;
|
|
||||||
|
|
||||||
mod raw_fd_num;
|
|
||||||
pub use raw_fd_num::*;
|
|
||||||
|
|
||||||
mod borrowed_fd;
|
|
||||||
pub use borrowed_fd::*;
|
|
||||||
|
|
||||||
use std::os::unix::io::{FromRawFd, OwnedFd, RawFd};
|
use std::os::unix::io::{FromRawFd, OwnedFd, RawFd};
|
||||||
|
|
||||||
use nix::fcntl::{fcntl, FdFlag, F_GETFD, F_SETFD};
|
use nix::fcntl::{fcntl, FdFlag, F_GETFD, F_SETFD};
|
@ -1,40 +0,0 @@
|
|||||||
#![allow(deprecated)]
|
|
||||||
|
|
||||||
use std::marker::PhantomData;
|
|
||||||
use std::os::unix::io::{AsRawFd, RawFd};
|
|
||||||
|
|
||||||
/// A borrowed file raw descriptor. (A `RawFd` with an attached lifetime).
|
|
||||||
///
|
|
||||||
/// For when using `&FdRef` is not an option.
|
|
||||||
///
|
|
||||||
/// This specifically does not implement `IntoRawFd` or `FromRawFd`, since those would drop life
|
|
||||||
/// times.
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
|
||||||
#[deprecated(note = "use std::os::unix::io::BorrowedFd instead")]
|
|
||||||
pub struct BorrowedFd<'a> {
|
|
||||||
fd: RawFd,
|
|
||||||
_borrow: PhantomData<&'a RawFd>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> BorrowedFd<'a> {
|
|
||||||
#[inline]
|
|
||||||
pub fn new<T: ?Sized + AsRawFd>(fd: &T) -> Self {
|
|
||||||
Self {
|
|
||||||
fd: fd.as_raw_fd(),
|
|
||||||
_borrow: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AsRawFd for BorrowedFd<'_> {
|
|
||||||
fn as_raw_fd(&self) -> RawFd {
|
|
||||||
self.fd
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, T: ?Sized + AsRawFd> From<&'a T> for BorrowedFd<'a> {
|
|
||||||
#[inline]
|
|
||||||
fn from(fd: &'a T) -> Self {
|
|
||||||
Self::new(fd)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,134 +0,0 @@
|
|||||||
use std::borrow::Borrow;
|
|
||||||
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
|
|
||||||
|
|
||||||
use nix::fcntl::OFlag;
|
|
||||||
use nix::sys::stat::Mode;
|
|
||||||
use nix::NixPath;
|
|
||||||
|
|
||||||
/// 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).
|
|
||||||
#[derive(Debug)]
|
|
||||||
#[deprecated(note = "use std::os::unix::io::OwnedFd instead")]
|
|
||||||
pub struct Fd(pub RawFd);
|
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl Drop for Fd {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
// `>= 0` instead of `!= -1` to also handle things like AT_FDCWD
|
|
||||||
if self.0 >= 0 {
|
|
||||||
unsafe {
|
|
||||||
libc::close(self.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl Fd {
|
|
||||||
#[deprecated(note = "use proxmox_sys::fd::cwd instead")]
|
|
||||||
pub const fn cwd() -> Self {
|
|
||||||
Self(libc::AT_FDCWD)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[deprecated(note = "use proxmox_sys::fd::open instead")]
|
|
||||||
pub fn open<P>(path: &P, oflag: OFlag, mode: Mode) -> Result<Self, nix::Error>
|
|
||||||
where
|
|
||||||
P: ?Sized + NixPath,
|
|
||||||
{
|
|
||||||
nix::fcntl::open(path, oflag, mode).map(Self)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[deprecated(note = "use proxmox_sys::fd::openat instead")]
|
|
||||||
pub fn openat<D, P>(dirfd: &D, path: &P, oflag: OFlag, mode: Mode) -> Result<Self, nix::Error>
|
|
||||||
where
|
|
||||||
D: AsRawFd,
|
|
||||||
P: ?Sized + NixPath,
|
|
||||||
{
|
|
||||||
nix::fcntl::openat(dirfd.as_raw_fd(), path, oflag, mode).map(Self)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Borrow this file descriptor as an `&FdRef`.
|
|
||||||
pub fn as_fd_ref(&self) -> &FdRef {
|
|
||||||
unsafe { &*(&self.0 as *const RawFd as *const FdRef) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl FromRawFd for Fd {
|
|
||||||
unsafe fn from_raw_fd(fd: RawFd) -> Self {
|
|
||||||
Self(fd)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl AsRawFd for Fd {
|
|
||||||
fn as_raw_fd(&self) -> RawFd {
|
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl IntoRawFd for Fd {
|
|
||||||
fn into_raw_fd(mut self) -> RawFd {
|
|
||||||
let fd = self.0;
|
|
||||||
self.0 = -1;
|
|
||||||
fd
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl AsRef<FdRef> for Fd {
|
|
||||||
fn as_ref(&self) -> &FdRef {
|
|
||||||
self.as_fd_ref()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl Borrow<FdRef> for Fd {
|
|
||||||
fn borrow(&self) -> &FdRef {
|
|
||||||
self.as_fd_ref()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl std::ops::Deref for Fd {
|
|
||||||
type Target = FdRef;
|
|
||||||
|
|
||||||
fn deref(&self) -> &FdRef {
|
|
||||||
self.as_fd_ref()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl From<OwnedFd> for Fd {
|
|
||||||
fn from(fd: OwnedFd) -> Fd {
|
|
||||||
Fd(fd.into_raw_fd())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl From<Fd> for OwnedFd {
|
|
||||||
fn from(fd: Fd) -> OwnedFd {
|
|
||||||
unsafe { OwnedFd::from_raw_fd(fd.into_raw_fd()) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A reference to a raw file descriptor. (Strongly typed `&RawFd` which is not equivalent to an
|
|
||||||
/// `&i32`.
|
|
||||||
///
|
|
||||||
/// `RawFd` should only be used as parameter type for functions, but never as a return type, since
|
|
||||||
/// it is not clear whether the returned integer is borrowed or owned. Instead, functions should
|
|
||||||
/// return `Fd` or `&FdRef`.
|
|
||||||
///
|
|
||||||
/// This specifically does not implement `IntoRawFd` or `FromRawFd`, since those would drop life
|
|
||||||
/// times.
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
|
||||||
pub enum FdRef {}
|
|
||||||
|
|
||||||
impl AsRawFd for FdRef {
|
|
||||||
#[inline]
|
|
||||||
fn as_raw_fd(&self) -> RawFd {
|
|
||||||
unsafe { *(self as *const Self as *const RawFd) }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
#![allow(deprecated)]
|
|
||||||
|
|
||||||
use std::borrow::Borrow;
|
|
||||||
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
|
|
||||||
|
|
||||||
use super::FdRef;
|
|
||||||
|
|
||||||
/// Raw file descriptor by number. Thin wrapper to provide `AsRawFd` which a simple `RawFd` does
|
|
||||||
/// not since it's just an `i32`.
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
|
||||||
#[deprecated(note = "use OwnedFd, &OwnedFd, BorrowedFd or just &RawFd instead")]
|
|
||||||
pub struct RawFdNum(RawFd);
|
|
||||||
|
|
||||||
impl RawFdNum {
|
|
||||||
/// Borrow this file descriptor as an `&FdRef`.
|
|
||||||
pub fn as_fd_ref(&self) -> &FdRef {
|
|
||||||
unsafe { &*(&self.0 as *const RawFd as *const FdRef) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AsRawFd for RawFdNum {
|
|
||||||
fn as_raw_fd(&self) -> RawFd {
|
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromRawFd for RawFdNum {
|
|
||||||
unsafe fn from_raw_fd(fd: RawFd) -> Self {
|
|
||||||
Self(fd)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoRawFd for RawFdNum {
|
|
||||||
fn into_raw_fd(self) -> RawFd {
|
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AsRef<FdRef> for RawFdNum {
|
|
||||||
fn as_ref(&self) -> &FdRef {
|
|
||||||
self.as_fd_ref()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Borrow<FdRef> for RawFdNum {
|
|
||||||
fn borrow(&self) -> &FdRef {
|
|
||||||
self.as_fd_ref()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::ops::Deref for RawFdNum {
|
|
||||||
type Target = FdRef;
|
|
||||||
|
|
||||||
fn deref(&self) -> &FdRef {
|
|
||||||
self.as_fd_ref()
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,33 +10,12 @@ use proxmox_io::vec;
|
|||||||
/// `"security.capability"` as a CStr to avoid typos.
|
/// `"security.capability"` as a CStr to avoid typos.
|
||||||
pub const XATTR_NAME_FCAPS: &CStr = c"security.capability";
|
pub const XATTR_NAME_FCAPS: &CStr = c"security.capability";
|
||||||
|
|
||||||
/// `"security.capability"` as a CStr to avoid typos.
|
|
||||||
#[deprecated = "use the XATTR_NAME_FCAPS constant instead"]
|
|
||||||
#[inline]
|
|
||||||
pub const fn xattr_name_fcaps() -> &'static CStr {
|
|
||||||
XATTR_NAME_FCAPS
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `"system.posix_acl_access"` as a CStr to avoid typos.
|
/// `"system.posix_acl_access"` as a CStr to avoid typos.
|
||||||
pub const XATTR_ACL_ACCESS: &CStr = c"system.posix_acl_access";
|
pub const XATTR_ACL_ACCESS: &CStr = c"system.posix_acl_access";
|
||||||
|
|
||||||
/// `"system.posix_acl_access"` as a CStr to avoid typos.
|
|
||||||
#[deprecated = "use the XATTR_ACL_ACCESS constant instead"]
|
|
||||||
#[inline]
|
|
||||||
pub const fn xattr_acl_access() -> &'static CStr {
|
|
||||||
XATTR_ACL_ACCESS
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `"system.posix_acl_default"` as a CStr to avoid typos.
|
/// `"system.posix_acl_default"` as a CStr to avoid typos.
|
||||||
pub const XATTR_ACL_DEFAULT: &CStr = c"system.posix_acl_default";
|
pub const XATTR_ACL_DEFAULT: &CStr = c"system.posix_acl_default";
|
||||||
|
|
||||||
/// `"system.posix_acl_default"` as a CStr to avoid typos.
|
|
||||||
#[deprecated = "use the XATTR_ACL_DEFAULT constant instead"]
|
|
||||||
#[inline]
|
|
||||||
pub const fn xattr_acl_default() -> &'static CStr {
|
|
||||||
XATTR_ACL_DEFAULT
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Result of `flistxattr`, allows iterating over the attributes as a list of `&CStr`s.
|
/// Result of `flistxattr`, allows iterating over the attributes as a list of `&CStr`s.
|
||||||
///
|
///
|
||||||
/// Listing xattrs produces a list separated by zeroes, inherently making them available as `&CStr`
|
/// Listing xattrs produces a list separated by zeroes, inherently making them available as `&CStr`
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
||||||
|
|
||||||
|
use std::os::fd::{FromRawFd, OwnedFd};
|
||||||
use std::os::unix::ffi::OsStrExt;
|
use std::os::unix::ffi::OsStrExt;
|
||||||
|
|
||||||
pub mod boot_mode;
|
pub mod boot_mode;
|
||||||
@ -21,9 +22,6 @@ pub mod systemd;
|
|||||||
mod worker_task_context;
|
mod worker_task_context;
|
||||||
pub use worker_task_context::*;
|
pub use worker_task_context::*;
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
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! {
|
||||||
@ -47,8 +45,7 @@ pub fn nodename() -> &'static str {
|
|||||||
|
|
||||||
/// Safe wrapper for `nix::unistd::pipe2` defaulting to `O_CLOEXEC`
|
/// Safe wrapper for `nix::unistd::pipe2` defaulting to `O_CLOEXEC`
|
||||||
/// and guarding the file descriptors.
|
/// and guarding the file descriptors.
|
||||||
#[allow(deprecated)]
|
pub fn pipe() -> Result<(OwnedFd, OwnedFd), nix::Error> {
|
||||||
pub fn pipe() -> Result<(Fd, Fd), nix::Error> {
|
|
||||||
let (pin, pout) = nix::unistd::pipe2(nix::fcntl::OFlag::O_CLOEXEC)?;
|
let (pin, pout) = nix::unistd::pipe2(nix::fcntl::OFlag::O_CLOEXEC)?;
|
||||||
Ok((Fd(pin), Fd(pout)))
|
Ok(unsafe { (OwnedFd::from_raw_fd(pin), OwnedFd::from_raw_fd(pout)) })
|
||||||
}
|
}
|
||||||
|
@ -25,18 +25,6 @@ pub fn stdout_terminal_size() -> (usize, usize) {
|
|||||||
(winsize.ws_row as usize, winsize.ws_col as usize)
|
(winsize.ws_row as usize, winsize.ws_col as usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether the current stdout is a tty.
|
|
||||||
#[deprecated(note = "Use std::io::stdout().is_terminal()")]
|
|
||||||
pub fn stdout_isatty() -> bool {
|
|
||||||
std::io::stdout().is_terminal()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns whether the current stdin is a tty.
|
|
||||||
#[deprecated(note = "Use std::io::stdin().is_terminal()")]
|
|
||||||
pub fn stdin_isatty() -> bool {
|
|
||||||
std::io::stdin().is_terminal()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum TtyOutput {
|
pub enum TtyOutput {
|
||||||
Stdout(std::io::Stdout),
|
Stdout(std::io::Stdout),
|
||||||
DevTty(OwnedFd),
|
DevTty(OwnedFd),
|
||||||
|
Loading…
Reference in New Issue
Block a user