cross-rs/cross · error
/proc/self/mountinfo is unavailable when target_os != linux
Error message
/proc/self/mountinfo is unavailable when target_os != linux
What it means
`docker_inspect_self_mountinfo` reads `/proc/self/mountinfo` to discover whether cross itself is running inside a container. That file only exists on Linux, so the function bails immediately when compiled/targeted for any other target_os instead of attempting a nonexistent path.
Solutions
- Only use this code path on Linux (it is guarded; if you hit it, the caller should skip mountinfo detection on non-Linux).
- Run cross on a Linux host or inside a Linux container where /proc/self/mountinfo exists.
- On macOS/Windows, rely on Docker Desktop defaults instead of self-mountinfo detection.
Defensive patterns
Strategy: type-guard
Validate before calling
function mountinfoAvailable() { return process.platform === 'linux'; } Type guard
const isLinux = () => process.platform === 'linux';
if (!isLinux()) {
// skip mountinfo-based container detection
} Prevention
- Gate mountinfo-dependent logic behind a Linux check.
- Run cross on Linux hosts or in Linux containers.
- Use Docker Desktop defaults on macOS/Windows instead of self-inspection.
When it happens
Trigger: Running cross on a non-Linux host (macOS, Windows) along a code path that inspects self mountinfo to determine if cross is containerized.
Common situations: Developers running cross natively on macOS/Windows expecting container-in-container detection; cross built for a non-Linux target where this inspection is requested.
Understand the failure class
Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.
Related errors
- invalid platform specified
- unsupported os in target, abi
- attempted to create already existing container.
- container was running.
- container was exited.
AI-assisted analysis of cross-rs/cross@8c1a8aa4b6 (2026-09-13).
Data as JSON: /api/errors/4be9bab5abd84c8a.
Report an issue: GitHub.
Appendix: source
Thrown at src/docker/shared.rs:1331
.join(", ")
)
}),
));
};
let image_name = pick.default_image_name();
if pick.platforms.is_empty() {
return Err(GetImageError::SpecifiedImageNoPlatform(image_name));
}
let mut image: PossibleImage = image_name.into();
image.toolchain = pick.platforms.to_vec();
Ok(image)
}
fn docker_inspect_self_mountinfo(engine: &Engine, msg_info: &mut MessageInfo) -> Result<String> {
if cfg!(not(target_os = "linux")) {
eyre::bail!("/proc/self/mountinfo is unavailable when target_os != linux");
}
// The ID for the current Docker container might be in mountinfo,
// somewhere in a mount root. Full IDs are 64-char hexadecimal
// strings, so the first matching path segment in a mount root
// containing /docker/ is likely to be what we're looking for. See:
// https://www.kernel.org/doc/Documentation/filesystems/proc.txt
// https://community.toradex.com/t/15240/4
let mountinfo = file::read("/proc/self/mountinfo")?;
let container_id = mountinfo
.lines()
.filter_map(|s| s.split(' ').nth(3))
.filter(|s| s.contains("/docker/"))
.flat_map(|s| s.split('/'))
.find(|s| s.len() == 64 && s.as_bytes().iter().all(u8::is_ascii_hexdigit))
.ok_or_else(|| eyre::eyre!("couldn't find container id in mountinfo"))?;
engineView on GitHub (pinned to 8c1a8aa4b6)