]> git.proxmox.com Git - pve-lxc-syscalld.git/blame - src/process/cgroups.rs
support pure cgroupv2 environments
[pve-lxc-syscalld.git] / src / process / cgroups.rs
CommitLineData
3bbd1db0
WB
1use std::collections::HashMap;
2use std::ffi::{OsStr, OsString};
3
92eface0 4#[derive(Default)]
3bbd1db0 5pub struct CGroups {
fe73c2fb 6 pub v1: Option<HashMap<String, OsString>>,
3bbd1db0
WB
7 pub v2: Option<OsString>,
8}
9
10impl CGroups {
11 pub fn new() -> Self {
92eface0 12 Self::default()
3bbd1db0
WB
13 }
14
15 pub fn get(&self, name: &str) -> Option<&OsStr> {
fe73c2fb
WB
16 self.v1
17 .as_ref()
18 .and_then(|v1| v1.get(name).map(|s| s.as_os_str()))
3bbd1db0
WB
19 }
20
21 pub fn v2(&self) -> Option<&OsStr> {
22 self.v2.as_ref().map(|s| s.as_os_str())
23 }
fe73c2fb
WB
24
25 pub fn has_v1(&self) -> bool {
26 self.v1.is_some()
27 }
3bbd1db0 28}