From 9ce206f6bc2ed786bf2c4e102c455765b9112f45 Mon Sep 17 00:00:00 2001 From: bin liu Date: Tue, 25 Aug 2020 10:50:52 +0800 Subject: [PATCH] probe cgroup v1 mount path Signed-off-by: bin liu --- src/hierarchies.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/hierarchies.rs b/src/hierarchies.rs index 368251a..204c887 100644 --- a/src/hierarchies.rs +++ b/src/hierarchies.rs @@ -126,11 +126,21 @@ fn find_v1_mount() -> Option { let mut fields = line.split_whitespace(); let index = line.find(" - ").unwrap(); let mut more_fields = line[index + 3..].split_whitespace().collect::>(); - let fstype = more_fields[0]; - if fstype == "tmpfs" && more_fields[2].contains("ro") { + if more_fields.len() == 0 { + continue; + } + if more_fields[0] == "cgroup" { + if more_fields.len() < 3 { + continue; + } let cgroups_mount = fields.nth(4).unwrap(); - info!("found cgroups at {:?}", cgroups_mount); - return Some(cgroups_mount.to_string()); + if let Some(parent) = std::path::Path::new(cgroups_mount).parent() { + if let Some(path) = parent.as_os_str().to_str() { + debug!("found cgroups {:?} from {:?}", path, cgroups_mount); + return Some(path.to_string()); + } + } + continue; } }