Skip to content

Commit 4526344

Browse files
MarkusPettersson98hulthe
authored andcommitted
Allow already mounted net_cls cgroup to be used for cgroup1 ST
1 parent 2954c83 commit 4526344

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

talpid-cgroup/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use anyhow::{Context as _, anyhow};
12
use std::ffi::OsStr;
23
use std::fs;
34
use 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")]
2021
pub 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

talpid-cgroup/src/v1.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ pub struct CGroup1 {
2929
impl 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

0 commit comments

Comments
 (0)