Checks whether a cgroup v2 controller (e.g. "cpu", "memory") is delegated to the current user session. Rootless Podman requires controllers to be delegated before it can set resource limits; without this, crun fails with "the requested cgroup controller is not available".
(controller: &str)
| 84 | /// delegated before it can set resource limits; without this, crun fails with |
| 85 | /// "the requested cgroup controller is not available". |
| 86 | fn cgroup_controller_available(controller: &str) -> bool { |
| 87 | let uid = unsafe { libc::getuid() }; |
| 88 | // Check the user's systemd service cgroup first, then the user slice |
| 89 | let paths = [ |
| 90 | format!("/sys/fs/cgroup/user.slice/user-{uid}.slice/user@{uid}.service/cgroup.controllers"), |
| 91 | format!("/sys/fs/cgroup/user.slice/user-{uid}.slice/cgroup.controllers"), |
| 92 | ]; |
| 93 | for path in &paths { |
| 94 | if let Ok(contents) = std::fs::read_to_string(path) { |
| 95 | return contents.split_whitespace().any(|c| c == controller); |
| 96 | } |
| 97 | } |
| 98 | // Non-cgroup-v2 or non-systemd: assume available (Docker handles this fine) |
| 99 | true |
| 100 | } |
| 101 | |
| 102 | /// Standard proxy environment variable names forwarded to/from containers. |
| 103 | /// Additional variables like JAVA_TOOL_OPTIONS and TSK_PROXY_HOST are handled separately. |
no outgoing calls
no test coverage detected