| 1 | use std::fs; |
| 2 | use std::process::Command; |
| 3 | |
| 4 | fn userns_available() -> bool { |
| 5 | let max = fs::read_to_string("/proc/sys/user/max_user_namespaces") |
| 6 | .ok() |
| 7 | .and_then(|s| s.trim().parse::<u64>().ok()) |
| 8 | .unwrap_or(0); |
| 9 | if max == 0 { |
| 10 | return false; |
| 11 | } |
| 12 | Command::new("unshare") |
| 13 | .args(["--user", "--map-root-user", "true"]) |
| 14 | .status() |
| 15 | .is_ok_and(|s| s.success()) |
| 16 | } |
| 17 | |
| 18 | pub fn can_run() -> bool { |
| 19 | if userns_available() { |
| 20 | true |
| 21 | } else { |
| 22 | eprintln!("skipping: unprivileged user namespaces are not available on this host"); |
| 23 | false |
| 24 | } |
| 25 | } |