File tree Expand file tree Collapse file tree 3 files changed +12
-11
lines changed Expand file tree Collapse file tree 3 files changed +12
-11
lines changed Original file line number Diff line number Diff line change 66
77//! This module handles cgroup operations. Start here!
88
9+ use log:: warn;
10+
911use crate :: fs:: error:: ErrorKind :: * ;
1012use 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 }
Original file line number Diff line number Diff line change 55//
66
77#![ allow( clippy:: unnecessary_unwrap) ]
8- use log:: * ;
98
109use std:: collections:: HashMap ;
1110use 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
Original file line number Diff line number Diff 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 ( ) ;
You can’t perform that action at this time.
0 commit comments