1pub mod fs;
8#[cfg(feature = "oci")]
9pub mod manager;
10#[cfg(feature = "oci")]
11pub use manager::{FsManager, Manager, SystemdManager};
12pub mod stats;
13pub use stats::CgroupStats;
14pub mod systemd;
15
16pub const CPU_SHARES_V1_MAX: u64 = 262144;
18pub const CPU_WEIGHT_V2_MAX: u64 = 10000;
20
21#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
23pub enum FreezerState {
24 Thawed,
26 Freezing,
28 Frozen,
30}
31
32#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
35pub struct CgroupPid {
36 pub pid: u64,
38}
39
40impl From<u64> for CgroupPid {
41 fn from(u: u64) -> CgroupPid {
42 CgroupPid { pid: u }
43 }
44}
45
46impl From<&std::process::Child> for CgroupPid {
47 fn from(u: &std::process::Child) -> CgroupPid {
48 CgroupPid { pid: u.id() as u64 }
49 }
50}
51
52#[cfg(test)]
53pub mod tests {
54 use std::fs;
55 use std::process::{Child, Command, Stdio};
56
57 pub fn spawn_sleep_inf() -> Child {
59 let child = Command::new("sleep")
60 .arg("infinity")
61 .spawn()
62 .expect("Failed to start mock subprocess");
63 child
64 }
65
66 pub fn spawn_yes() -> Child {
67 let devnull = fs::File::create("/dev/null").expect("cannot open /dev/null");
68 let child = Command::new("yes")
69 .stdout(Stdio::from(devnull))
70 .spawn()
71 .expect("Failed to start mock subprocess");
72 child
73 }
74
75 pub fn systemd_version() -> Option<usize> {
76 let output = Command::new("systemd").arg("--version").output().ok()?; if !output.status.success() {
79 return None;
80 }
81
82 let stdout = String::from_utf8_lossy(&output.stdout);
83
84 let first_line = stdout.lines().next()?;
86 let mut words = first_line.split_whitespace();
87
88 words.next()?; let version_str = words.next()?; version_str.parse::<usize>().ok()
92 }
93}