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