#[cfg_attr(
not(target_os = "linux"),
allow(
dead_code,
reason = "cgroup::reach is this function's only caller and is linux-gated; kept host-agnostic"
)
)]
pub(crate) fn is_at_or_under(path: &str, leaf: &str) -> bool {
path.strip_prefix(leaf)
.is_some_and(|rest| rest.is_empty() || rest.starts_with('/'))
}
#[cfg_attr(
not(target_os = "linux"),
allow(
dead_code,
reason = "cgroup::leaf is this function's only caller and is linux-gated; kept host-agnostic"
)
)]
pub(crate) fn parse_v2_relative_path(proc_self_cgroup: &str) -> Option<&str> {
for line in proc_self_cgroup.lines() {
if let Some(rest) = line.strip_prefix("0::") {
return Some(rest);
}
}
None
}
#[cfg_attr(
not(target_os = "linux"),
allow(
dead_code,
reason = "cgroup::leaf is this function's only caller and is linux-gated; kept host-agnostic"
)
)]
pub(crate) fn summarize_cgroup_controllers(proc_self_cgroup: &str) -> (usize, String) {
let mut controllers: Vec<&str> = Vec::new();
for line in proc_self_cgroup.lines() {
match line.match_indices(':').nth(1) {
Some((path_start, _)) => controllers.push(&line[..path_start]),
None => controllers.push("<unparseable line>"),
}
}
let rendered = if controllers.is_empty() {
"no controllers".to_string()
} else {
controllers.join(", ")
};
(controllers.len(), rendered)
}
#[cfg_attr(
not(target_os = "linux"),
allow(
dead_code,
reason = "cgroup::leaf is this function's only caller and is linux-gated; kept host-agnostic"
)
)]
pub(crate) fn parse_populated(contents: &str) -> Option<bool> {
for line in contents.lines() {
if let Some(rest) = line.strip_prefix("populated ") {
return match rest.trim() {
"0" => Some(false),
"1" => Some(true),
_ => None,
};
}
}
None
}
#[cfg_attr(
not(target_os = "linux"),
allow(
dead_code,
reason = "cgroup::leaf is this function's only caller and is linux-gated; kept host-agnostic"
)
)]
pub(crate) fn parse_proc_stat_state(stat: &str) -> Option<char> {
let tail = &stat[stat.rfind(')')? + 1..];
tail.split_whitespace().next()?.chars().next()
}
#[cfg(test)]
#[path = "parse_tests.rs"]
mod parse_tests;