From 17a6c6b842c5e9a09a05d716b5d90bc3d42ef14d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Medina?= Date: Wed, 20 Sep 2023 19:57:58 -0700 Subject: [PATCH] fix misidentification of cgroup v2 in musl targets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When compiling for a musl target, use the same CGROUP2_SUPER_MAGIC constant that we use for other linux targets Signed-off-by: Andrés Medina --- src/hierarchies.rs | 37 +++++-------------------------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/src/hierarchies.rs b/src/hierarchies.rs index 37a9bac..db505e7 100644 --- a/src/hierarchies.rs +++ b/src/hierarchies.rs @@ -309,43 +309,16 @@ impl Default for V2 { pub const UNIFIED_MOUNTPOINT: &str = "/sys/fs/cgroup"; -#[cfg(any( - all(target_os = "linux", not(target_env = "musl")), - target_os = "android" -))] pub fn is_cgroup2_unified_mode() -> bool { use nix::sys::statfs; let path = std::path::Path::new(UNIFIED_MOUNTPOINT); - let fs_stat = statfs::statfs(path); - if fs_stat.is_err() { - return false; - } + let fs_stat = match statfs::statfs(path) { + Ok(fs_stat) => fs_stat, + Err(_) => return false, + }; - // FIXME notwork, nix will not compile CGROUP2_SUPER_MAGIC because not(target_env = "musl") - fs_stat.unwrap().filesystem_type() == statfs::CGROUP2_SUPER_MAGIC -} - -pub const INIT_CGROUP_PATHS: &str = "/proc/1/cgroup"; - -#[cfg(all(target_os = "linux", target_env = "musl"))] -pub fn is_cgroup2_unified_mode() -> bool { - let lines = fs::read_to_string(INIT_CGROUP_PATHS); - if lines.is_err() { - return false; - } - - for line in lines.unwrap().lines() { - let fields: Vec<&str> = line.split(':').collect(); - if fields.len() != 3 { - continue; - } - if fields[0] != "0" { - return false; - } - } - - true + fs_stat.filesystem_type() == statfs::CGROUP2_SUPER_MAGIC } pub fn auto() -> Box {