clippy fixes

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2021-06-11 10:55:47 +02:00
parent 69eff2a1b2
commit a03af34bb5
6 changed files with 14 additions and 15 deletions

View File

@ -46,7 +46,7 @@ impl Client {
}
async fn handle_syscall(&self, msg: &mut ProxyMessageBuffer) -> Result<(), Error> {
let result = match Self::handle_syscall_do(&msg).await {
let result = match Self::handle_syscall_do(msg).await {
Ok(r) => r,
Err(err) => {
// handle the various kinds of errors we may get:

View File

@ -7,7 +7,6 @@ use std::task::{Context, Poll};
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
use crate::error::io_err_other;
use crate::io::polled_fd::PolledFd;
use crate::io::rw_traits;
use crate::tools::Fd;
@ -91,14 +90,12 @@ impl<RW: rw_traits::HasRead> AsyncRead for Pipe<RW> {
self.fd.wrap_read(cx, || {
let fd = self.as_raw_fd();
let mem = buf.initialize_unfilled();
let size = libc::size_t::try_from(mem.len()).map_err(io_err_other)?;
c_result!(unsafe { libc::read(fd, mem.as_mut_ptr() as *mut libc::c_void, size) }).map(
|received| {
c_result!(unsafe { libc::read(fd, mem.as_mut_ptr() as *mut libc::c_void, mem.len()) })
.map(|received| {
if received > 0 {
buf.advance(received as usize)
}
},
)
})
})
}
}
@ -111,8 +108,7 @@ impl<RW: rw_traits::HasWrite> AsyncWrite for Pipe<RW> {
) -> Poll<io::Result<usize>> {
self.fd.wrap_write(cx, || {
let fd = self.as_raw_fd();
let size = libc::size_t::try_from(buf.len()).map_err(io_err_other)?;
c_result!(unsafe { libc::write(fd, buf.as_ptr() as *const libc::c_void, size) })
c_result!(unsafe { libc::write(fd, buf.as_ptr() as *const libc::c_void, buf.len()) })
.map(|res| res as usize)
})
}

View File

@ -393,7 +393,7 @@ impl ProxyMessageBuffer {
/// Checked way to get a `dev_t` argument.
#[inline]
pub fn arg_dev_t(&self, arg: u32) -> Result<nix::sys::stat::dev_t, Error> {
nix::sys::stat::dev_t::try_from(self.arg(arg)?).map_err(|_| Errno::EINVAL.into())
self.arg(arg)
}
/// Checked way to get a file descriptor argument.

View File

@ -19,7 +19,7 @@ impl CGroups {
}
pub fn v2(&self) -> Option<&OsStr> {
self.v2.as_ref().map(|s| s.as_os_str())
self.v2.as_deref()
}
pub fn has_v1(&self) -> bool {

View File

@ -10,6 +10,7 @@ use anyhow::{bail, Error};
use libc::pid_t;
use crate::capability::Capabilities;
use crate::error::io_err_other;
use crate::nsfd::{ns_type, NsFd};
use crate::tools::Fd;
@ -38,6 +39,7 @@ impl PidFd {
/// The file descriptor must already be a valid pidfd, this is not checked. This function only
/// fails if reading the pid from the pidfd's proc entry fails.
pub unsafe fn try_from_fd(fd: Fd) -> io::Result<Self> {
#[allow(clippy::unnecessary_cast)] // pid_t is a type alias
let mut this = Self(fd.into_raw_fd(), -1 as pid_t);
let pid = this.read_pid()?;
this.1 = pid;
@ -145,24 +147,24 @@ impl PidFd {
#[inline]
fn check_u64_hex(value: Option<&str>) -> io::Result<u64> {
Ok(u64::from_str_radix(
u64::from_str_radix(
value.ok_or_else(|| {
io::Error::new(io::ErrorKind::Other, "bad numeric property line in proc")
})?,
16,
)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?)
.map_err(io_err_other)
}
#[inline]
fn check_u32_oct(value: Option<&str>) -> io::Result<u32> {
Ok(u32::from_str_radix(
u32::from_str_radix(
value.ok_or_else(|| {
io::Error::new(io::ErrorKind::Other, "bad numeric property line in proc")
})?,
8,
)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?)
.map_err(io_err_other)
}
let mut ids = Uids::default();

View File

@ -43,6 +43,7 @@ fn check_mknod_dev(mode: stat::mode_t, dev: stat::dev_t) -> bool {
let major = stat::major(dev);
let minor = stat::minor(dev);
#[allow(clippy::match_like_matches_macro)]
match (sflag, major, minor) {
(libc::S_IFREG, 0, 0) => true, // touch
(libc::S_IFCHR, 0, 0) => true, // whiteout