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