Improve the error management when /proc is not mounted
This PR does two things: * Triggers an error on GNU/Linux & Android when /proc/self/exe doesn't exist * Handle the error properly
This commit is contained in:
parent
208d23a996
commit
1b6a182cf1
@ -159,9 +159,14 @@ pub fn get_or_default_sysroot() -> PathBuf {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
match canonicalize(env::current_exe().ok()) {
|
match env::current_exe() {
|
||||||
Some(mut p) => { p.pop(); p.pop(); p }
|
Ok(exe) => {
|
||||||
None => bug!("can't determine value for sysroot")
|
match canonicalize(Some(exe)) {
|
||||||
|
Some(mut p) => { p.pop(); p.pop(); return p; },
|
||||||
|
None => bug!("can't determine value for sysroot")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(ref e) => panic!(format!("failed to get current_exe: {}", e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,7 +253,12 @@ pub fn current_exe() -> io::Result<PathBuf> {
|
|||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))]
|
#[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))]
|
||||||
pub fn current_exe() -> io::Result<PathBuf> {
|
pub fn current_exe() -> io::Result<PathBuf> {
|
||||||
::fs::read_link("/proc/self/exe")
|
let selfexe = PathBuf::from("/proc/self/exe");
|
||||||
|
if selfexe.exists() {
|
||||||
|
::fs::read_link(selfexe)
|
||||||
|
} else {
|
||||||
|
Err(io::Error::new(io::ErrorKind::Other, "no /proc/self/exe available. Is /proc mounted?"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||||
|
Loading…
Reference in New Issue
Block a user