diff --git a/src/cgroup.rs b/src/cgroup.rs index 4dda0c0..c28f022 100644 --- a/src/cgroup.rs +++ b/src/cgroup.rs @@ -311,9 +311,8 @@ impl Cgroup { pub const UNIFIED_MOUNTPOINT: &str = "/sys/fs/cgroup"; -fn enable_controllers(controllers: &[String], path: &PathBuf) { - let mut f = path.clone(); - f.push("cgroup.subtree_control"); +fn enable_controllers(controllers: &[String], path: &Path) { + let f = path.join("cgroup.subtree_control"); for c in controllers { let body = format!("+{}", c); let _rest = fs::write(f.as_path(), body.as_bytes()); diff --git a/src/cgroup_builder.rs b/src/cgroup_builder.rs index e410fd8..09eca24 100644 --- a/src/cgroup_builder.rs +++ b/src/cgroup_builder.rs @@ -240,10 +240,10 @@ impl DeviceResourceBuilder { access: Vec, ) -> DeviceResourceBuilder { self.cgroup.resources.devices.devices.push(DeviceResource { + allow, + devtype, major, minor, - devtype, - allow, access, }); self diff --git a/src/error.rs b/src/error.rs index 26c86a8..cea6a39 100644 --- a/src/error.rs +++ b/src/error.rs @@ -76,6 +76,7 @@ impl fmt::Display for Error { impl StdError for Error { fn cause(&self) -> Option<&dyn StdError> { + #[allow(clippy::manual_map)] match self.cause { Some(ref x) => Some(&**x), None => None, diff --git a/src/events.rs b/src/events.rs index 86f8f75..08c25de 100644 --- a/src/events.rs +++ b/src/events.rs @@ -8,7 +8,7 @@ use nix::sys::eventfd; use std::fs::{self, File}; use std::io::Read; use std::os::unix::io::{AsRawFd, FromRawFd}; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::sync::mpsc::{self, Receiver}; use std::thread; @@ -17,18 +17,18 @@ use crate::error::*; // notify_on_oom returns channel on which you can expect event about OOM, // if process died without OOM this channel will be closed. -pub fn notify_on_oom_v2(key: &str, dir: &PathBuf) -> Result> { +pub fn notify_on_oom_v2(key: &str, dir: &Path) -> Result> { register_memory_event(key, dir, "memory.oom_control", "") } // notify_on_oom returns channel on which you can expect event about OOM, // if process died without OOM this channel will be closed. -pub fn notify_on_oom_v1(key: &str, dir: &PathBuf) -> Result> { +pub fn notify_on_oom_v1(key: &str, dir: &Path) -> Result> { register_memory_event(key, dir, "memory.oom_control", "") } // level is one of "low", "medium", or "critical" -pub fn notify_memory_pressure(key: &str, dir: &PathBuf, level: &str) -> Result> { +pub fn notify_memory_pressure(key: &str, dir: &Path, level: &str) -> Result> { if level != "low" && level != "medium" && level != "critical" { return Err(Error::from_string(format!( "invalid pressure level {}", @@ -41,7 +41,7 @@ pub fn notify_memory_pressure(key: &str, dir: &PathBuf, level: &str) -> Result Result> { diff --git a/src/lib.rs b/src/lib.rs index 52e63be..b8b2385 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -365,11 +365,9 @@ where .map(|file| { let bf = BufReader::new(file); let mut v = Vec::new(); - for line in bf.lines() { - if let Ok(line) = line { - let n = line.trim().parse().unwrap_or(0u64); - v.push(n); - } + for line in bf.lines().flatten() { + let n = line.trim().parse().unwrap_or(0u64); + v.push(n); } v.into_iter().map(CgroupPid::from).collect() }) @@ -383,7 +381,7 @@ where // remove_dir aims to remove cgroup path. It does so recursively, // by removing any subdirectories (sub-cgroups) first. -fn remove_dir(dir: &PathBuf) -> Result<()> { +fn remove_dir(dir: &Path) -> Result<()> { // try the fast path first. if fs::remove_dir(dir).is_ok() { return Ok(());