Skip to content

Commit

Permalink
Rollup merge of rust-lang#42056 - sylvestre:master, r=alexcrichton
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Mark-Simulacrum authored May 19, 2017
2 parents db01c94 + 1b6a182 commit 0011828
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/librustc/session/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,14 @@ pub fn get_or_default_sysroot() -> PathBuf {
})
}

match canonicalize(env::current_exe().ok()) {
Some(mut p) => { p.pop(); p.pop(); p }
None => bug!("can't determine value for sysroot")
match env::current_exe() {
Ok(exe) => {
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))
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/libstd/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,12 @@ pub fn current_exe() -> io::Result<PathBuf> {

#[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))]
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"))]
Expand Down

0 comments on commit 0011828

Please sign in to comment.