File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed
Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change 1+ use anyhow:: { Context as _, anyhow} ;
12use std:: ffi:: OsStr ;
23use std:: fs;
34use std:: os:: unix:: ffi:: OsStrExt ;
@@ -19,9 +20,12 @@ pub const DEFAULT_NET_CLS_DIR: &str = "/sys/fs/cgroup/net_cls";
1920#[ error( "CGroup error" ) ]
2021pub struct Error ( #[ from] anyhow:: Error ) ;
2122
22- /// Find the path of the cgroup v1 net_cls controller mount if it exists
23- pub fn find_net_cls_mount ( ) -> std:: io:: Result < Option < PathBuf > > {
24- let mounts = fs:: read ( "/proc/mounts" ) ?;
23+ /// Find the path of the cgroup v1 net_cls controller mount if it exists.
24+ ///
25+ /// Returns an error if `/proc/mounts` does not exist.
26+ pub fn find_net_cls_mount ( ) -> Result < Option < PathBuf > , Error > {
27+ let mounts =
28+ fs:: read ( "/proc/mounts" ) . with_context ( || anyhow ! ( "Failed to stat `/proc/mounts`" ) ) ?;
2529 Ok ( find_net_cls_mount_inner ( & mounts) )
2630}
2731
Original file line number Diff line number Diff line change @@ -29,7 +29,9 @@ pub struct CGroup1 {
2929impl CGroup1 {
3030 /// Open the root net_cls cgroup at [`DEFAULT_NET_CLS_DIR`], creating if if it doesn't exist.
3131 pub fn open_root ( ) -> Result < Self , super :: Error > {
32- // TODO: find_net_cls_mount()??
32+ if let Some ( net_cls_path) = find_net_cls_mount ( ) ? {
33+ return Self :: open ( net_cls_path) ;
34+ }
3335
3436 // mkdir and mount the net_cls dir if it doesn't exist
3537 // https://www.kernel.org/doc/Documentation/cgroup-v1/net_cls.txt
You can’t perform that action at this time.
0 commit comments