{"record":{"id":"4be9bab5abd84c8a","repo":"cross-rs/cross","slug":"proc-self-mountinfo-is-unavailable-when-target-os-linux","errorCode":null,"errorMessage":"/proc/self/mountinfo is unavailable when target_os != linux","messagePattern":"/proc/self/mountinfo is unavailable when target_os != linux","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/docker/shared.rs","lineNumber":1331,"sourceCode":"                        .join(\", \")\n                )\n            }),\n        ));\n    };\n\n    let image_name = pick.default_image_name();\n    if pick.platforms.is_empty() {\n        return Err(GetImageError::SpecifiedImageNoPlatform(image_name));\n    }\n\n    let mut image: PossibleImage = image_name.into();\n    image.toolchain = pick.platforms.to_vec();\n    Ok(image)\n}\n\nfn docker_inspect_self_mountinfo(engine: &Engine, msg_info: &mut MessageInfo) -> Result<String> {\n    if cfg!(not(target_os = \"linux\")) {\n        eyre::bail!(\"/proc/self/mountinfo is unavailable when target_os != linux\");\n    }\n\n    // The ID for the current Docker container might be in mountinfo,\n    // somewhere in a mount root. Full IDs are 64-char hexadecimal\n    // strings, so the first matching path segment in a mount root\n    // containing /docker/ is likely to be what we're looking for. See:\n    // https://www.kernel.org/doc/Documentation/filesystems/proc.txt\n    // https://community.toradex.com/t/15240/4\n    let mountinfo = file::read(\"/proc/self/mountinfo\")?;\n    let container_id = mountinfo\n        .lines()\n        .filter_map(|s| s.split(' ').nth(3))\n        .filter(|s| s.contains(\"/docker/\"))\n        .flat_map(|s| s.split('/'))\n        .find(|s| s.len() == 64 && s.as_bytes().iter().all(u8::is_ascii_hexdigit))\n        .ok_or_else(|| eyre::eyre!(\"couldn't find container id in mountinfo\"))?;\n\n    engine","sourceCodeStart":1313,"sourceCodeEnd":1349,"githubUrl":"https://github.com/cross-rs/cross/blob/8c1a8aa4b661711f4b7b6ac07c2e8929ce2f7d27/src/docker/shared.rs#L1313-L1349","documentation":"`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.","triggerScenarios":"Running cross on a non-Linux host (macOS, Windows) along a code path that inspects self mountinfo to determine if cross is containerized.","commonSituations":"Developers running cross natively on macOS/Windows expecting container-in-container detection; cross built for a non-Linux target where this inspection is requested.","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."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"function mountinfoAvailable() { return process.platform === 'linux'; }","typeGuard":"const isLinux = () => process.platform === 'linux';\nif (!isLinux()) {\n  // skip mountinfo-based container detection\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["linux","platform","procfs","container"],"backgroundTag":"unsupported-platform","analyzedSha":"8c1a8aa4b661711f4b7b6ac07c2e8929ce2f7d27","analyzedAt":"2026-09-13T15:10:43.988Z","contentChangedAt":"2026-09-13T15:10:43.988Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}