fix(Controller): Errors are hidden by defaul

Fixed an error hidden during the creation of cgroup,
which resulted in subsequent error propagation

Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
This commit is contained in:
jokemanfire
2025-08-01 11:01:20 +08:00
committed by 胡丁洋10346053
parent 5d74a1dfc9
commit a30729bcf1
3 changed files with 10 additions and 11 deletions

View File

@@ -84,9 +84,9 @@ impl Cgroup {
if self.hier.v2() {
create_v2_cgroup(self.hier.root(), &self.path, &self.specified_controllers)
} else {
for subsystem in &self.subsystems {
subsystem.to_controller().create();
}
self.subsystems
.iter()
.try_for_each(|subsystem| subsystem.to_controller().create())?;
Ok(())
}
}

View File

@@ -5,7 +5,6 @@
//
#![allow(clippy::unnecessary_unwrap)]
use log::*;
use std::collections::HashMap;
use std::fmt;
@@ -265,7 +264,7 @@ pub trait Controller {
fn apply(&self, res: &Resources) -> Result<()>;
/// Create this controller
fn create(&self);
fn create(&self) -> Result<()>;
/// Does this controller already exist?
fn exists(&self) -> bool;
@@ -323,14 +322,14 @@ where
}
/// Create this controller
fn create(&self) {
fn create(&self) -> Result<()> {
self.verify_path()
.unwrap_or_else(|_| panic!("path should be valid: {:?}", self.path()));
match ::std::fs::create_dir_all(self.get_path()) {
Ok(_) => self.post_create(),
Err(e) => warn!("error create_dir: {:?} error: {:?}", self.get_path(), e),
}
std::fs::create_dir_all(self.get_path())
.map_err(|err| Error::with_cause(ErrorKind::FsError, err))?;
self.post_create();
Ok(())
}
/// Set notify_on_release

View File

@@ -248,7 +248,7 @@ pub mod tests {
String::from_utf8_lossy(&output.stdout).to_string()
}
fn start_default_cgroup(pid: CgroupPid, unit: &str) -> SystemdClient {
fn start_default_cgroup(pid: CgroupPid, unit: &'_ str) -> SystemdClient<'_> {
let mut props = PropertiesBuilder::default_cgroup(TEST_SLICE, unit).build();
props.push((PIDS, Value::Array(vec![pid.pid as u32].into())));
let cgroup = SystemdClient::new(unit, props).unwrap();