mirror of
https://git.proxmox.com/git/proxmox
synced 2025-05-30 23:01:13 +00:00
[clippy] sys: simplifications and optimizations
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
05b432c422
commit
a11f6e88f8
@ -3,6 +3,7 @@
|
|||||||
// from /usr/include/linux/magic.h
|
// from /usr/include/linux/magic.h
|
||||||
// and from casync util.h
|
// and from casync util.h
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
|
#[allow(clippy::unreadable_literal)]
|
||||||
mod consts {
|
mod consts {
|
||||||
pub const BINFMTFS_MAGIC : i64 = 0x42494e4d;
|
pub const BINFMTFS_MAGIC : i64 = 0x42494e4d;
|
||||||
pub const CGROUP2_SUPER_MAGIC : i64 = 0x63677270;
|
pub const CGROUP2_SUPER_MAGIC : i64 = 0x63677270;
|
||||||
|
@ -73,7 +73,7 @@ pub fn read_proc_starttime(pid: libc::pid_t) -> Result<u64, Error> {
|
|||||||
|
|
||||||
pub fn check_process_running(pid: libc::pid_t) -> Option<ProcFsPidStat> {
|
pub fn check_process_running(pid: libc::pid_t) -> Option<ProcFsPidStat> {
|
||||||
if let Ok(info) = read_proc_pid_stat(pid) {
|
if let Ok(info) = read_proc_pid_stat(pid) {
|
||||||
if info.status != 'Z' as u8 {
|
if info.status != b'Z' {
|
||||||
return Some(info);
|
return Some(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ pub fn read_proc_uptime() -> Result<(f64, f64), Error> {
|
|||||||
let mut values = line.split_whitespace().map(|v| v.parse::<f64>());
|
let mut values = line.split_whitespace().map(|v| v.parse::<f64>());
|
||||||
|
|
||||||
match (values.next(), values.next()) {
|
match (values.next(), values.next()) {
|
||||||
(Some(Ok(up)), Some(Ok(idle))) => return Ok((up, idle)),
|
(Some(Ok(up)), Some(Ok(idle))) => Ok((up, idle)),
|
||||||
_ => bail!("Error while parsing '{}'", path),
|
_ => bail!("Error while parsing '{}'", path),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,7 +195,7 @@ pub fn read_cpuinfo() -> Result<ProcFsCPUInfo, Error> {
|
|||||||
if content.is_empty() {
|
if content.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let mut content_iter = content.split(":");
|
let mut content_iter = content.split(':');
|
||||||
match (content_iter.next(), content_iter.next()) {
|
match (content_iter.next(), content_iter.next()) {
|
||||||
(Some(key), Some(value)) => match key.trim_end() {
|
(Some(key), Some(value)) => match key.trim_end() {
|
||||||
"processor" => cpuinfo.cpus += 1,
|
"processor" => cpuinfo.cpus += 1,
|
||||||
@ -254,7 +254,7 @@ pub fn read_proc_net_dev() -> Result<Vec<ProcFsNetDev>, Error> {
|
|||||||
for line in BufReader::new(&file).lines().skip(2) {
|
for line in BufReader::new(&file).lines().skip(2) {
|
||||||
let content = line?;
|
let content = line?;
|
||||||
let mut iter = content.split_whitespace();
|
let mut iter = content.split_whitespace();
|
||||||
match (iter.next(), iter.next(), iter.skip(7).next()) {
|
match (iter.next(), iter.next(), iter.nth(7)) {
|
||||||
(Some(device), Some(receive), Some(send)) => {
|
(Some(device), Some(receive), Some(send)) => {
|
||||||
result.push(ProcFsNetDev {
|
result.push(ProcFsNetDev {
|
||||||
device: device[..device.len() - 1].to_string(),
|
device: device[..device.len() - 1].to_string(),
|
||||||
@ -316,7 +316,7 @@ pub fn read_proc_net_route() -> Result<Vec<ProcFsNetRoute>, Error> {
|
|||||||
|
|
||||||
let mut next = || {
|
let mut next = || {
|
||||||
iter.next()
|
iter.next()
|
||||||
.ok_or(format_err!("Error while parsing '{}'", path))
|
.ok_or_else(|| format_err!("Error while parsing '{}'", path))
|
||||||
};
|
};
|
||||||
|
|
||||||
let (iface, dest, gateway) = (next()?, next()?, next()?);
|
let (iface, dest, gateway) = (next()?, next()?, next()?);
|
||||||
|
Loading…
Reference in New Issue
Block a user