Skip to content

Commit 1b6a182

Browse files
committed
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
1 parent 208d23a commit 1b6a182

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/librustc/session/filesearch.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,14 @@ pub fn get_or_default_sysroot() -> PathBuf {
159159
})
160160
}
161161

162-
match canonicalize(env::current_exe().ok()) {
163-
Some(mut p) => { p.pop(); p.pop(); p }
164-
None => bug!("can't determine value for sysroot")
162+
match env::current_exe() {
163+
Ok(exe) => {
164+
match canonicalize(Some(exe)) {
165+
Some(mut p) => { p.pop(); p.pop(); return p; },
166+
None => bug!("can't determine value for sysroot")
167+
}
168+
}
169+
Err(ref e) => panic!(format!("failed to get current_exe: {}", e))
165170
}
166171
}
167172

src/libstd/sys/unix/os.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,12 @@ pub fn current_exe() -> io::Result<PathBuf> {
253253

254254
#[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))]
255255
pub fn current_exe() -> io::Result<PathBuf> {
256-
::fs::read_link("/proc/self/exe")
256+
let selfexe = PathBuf::from("/proc/self/exe");
257+
if selfexe.exists() {
258+
::fs::read_link(selfexe)
259+
} else {
260+
Err(io::Error::new(io::ErrorKind::Other, "no /proc/self/exe available. Is /proc mounted?"))
261+
}
257262
}
258263

259264
#[cfg(any(target_os = "macos", target_os = "ios"))]

0 commit comments

Comments
 (0)