mirror of
https://github.com/kata-containers/cgroups-rs.git
synced 2026-08-05 02:13:23 +00:00
Fix clippy for rust 1.52
There are new lints are added in clippy for rust 1.52 Signed-off-by: Tim Zhang <tim@hyper.sh>
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -240,10 +240,10 @@ impl DeviceResourceBuilder {
|
||||
access: Vec<crate::devices::DevicePermissions>,
|
||||
) -> DeviceResourceBuilder {
|
||||
self.cgroup.resources.devices.devices.push(DeviceResource {
|
||||
allow,
|
||||
devtype,
|
||||
major,
|
||||
minor,
|
||||
devtype,
|
||||
allow,
|
||||
access,
|
||||
});
|
||||
self
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<Receiver<String>> {
|
||||
pub fn notify_on_oom_v2(key: &str, dir: &Path) -> Result<Receiver<String>> {
|
||||
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<Receiver<String>> {
|
||||
pub fn notify_on_oom_v1(key: &str, dir: &Path) -> Result<Receiver<String>> {
|
||||
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<Receiver<String>> {
|
||||
pub fn notify_memory_pressure(key: &str, dir: &Path, level: &str) -> Result<Receiver<String>> {
|
||||
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<R
|
||||
|
||||
fn register_memory_event(
|
||||
key: &str,
|
||||
cg_dir: &PathBuf,
|
||||
cg_dir: &Path,
|
||||
event_name: &str,
|
||||
arg: &str,
|
||||
) -> Result<Receiver<String>> {
|
||||
|
||||
@@ -365,12 +365,10 @@ where
|
||||
.map(|file| {
|
||||
let bf = BufReader::new(file);
|
||||
let mut v = Vec::new();
|
||||
for line in bf.lines() {
|
||||
if let Ok(line) = line {
|
||||
for line in bf.lines().flatten() {
|
||||
let n = line.trim().parse().unwrap_or(0u64);
|
||||
v.push(n);
|
||||
}
|
||||
}
|
||||
v.into_iter().map(CgroupPid::from).collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
@@ -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(());
|
||||
|
||||
Reference in New Issue
Block a user