Skip to content

Commit 9f398c7

Browse files
committed
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 <[email protected]>
1 parent 5d74a1d commit 9f398c7

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/fs/cgroup.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
//! This module handles cgroup operations. Start here!
88
9+
use log::warn;
10+
911
use crate::fs::error::ErrorKind::*;
1012
use crate::fs::error::*;
1113

@@ -84,9 +86,9 @@ impl Cgroup {
8486
if self.hier.v2() {
8587
create_v2_cgroup(self.hier.root(), &self.path, &self.specified_controllers)
8688
} else {
87-
for subsystem in &self.subsystems {
88-
subsystem.to_controller().create();
89-
}
89+
self.subsystems
90+
.iter()
91+
.try_for_each(|subsystem| subsystem.to_controller().create())?;
9092
Ok(())
9193
}
9294
}

src/fs/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//
66

77
#![allow(clippy::unnecessary_unwrap)]
8-
use log::*;
98

109
use std::collections::HashMap;
1110
use std::fmt;
@@ -265,7 +264,7 @@ pub trait Controller {
265264
fn apply(&self, res: &Resources) -> Result<()>;
266265

267266
/// Create this controller
268-
fn create(&self);
267+
fn create(&self) -> Result<()>;
269268

270269
/// Does this controller already exist?
271270
fn exists(&self) -> bool;
@@ -323,14 +322,14 @@ where
323322
}
324323

325324
/// Create this controller
326-
fn create(&self) {
325+
fn create(&self) -> Result<()> {
327326
self.verify_path()
328327
.unwrap_or_else(|_| panic!("path should be valid: {:?}", self.path()));
329328

330-
match ::std::fs::create_dir_all(self.get_path()) {
331-
Ok(_) => self.post_create(),
332-
Err(e) => warn!("error create_dir: {:?} error: {:?}", self.get_path(), e),
333-
}
329+
std::fs::create_dir_all(self.get_path())
330+
.map_err(|err| Error::with_cause(ErrorKind::FsError, err))?;
331+
self.post_create();
332+
Ok(())
334333
}
335334

336335
/// Set notify_on_release

src/systemd/dbus/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ pub mod tests {
248248
String::from_utf8_lossy(&output.stdout).to_string()
249249
}
250250

251-
fn start_default_cgroup(pid: CgroupPid, unit: &str) -> SystemdClient {
251+
fn start_default_cgroup(pid: CgroupPid, unit: &'_ str) -> SystemdClient<'_> {
252252
let mut props = PropertiesBuilder::default_cgroup(TEST_SLICE, unit).build();
253253
props.push((PIDS, Value::Array(vec![pid.pid as u32].into())));
254254
let cgroup = SystemdClient::new(unit, props).unwrap();

0 commit comments

Comments
 (0)