]> git.lizzy.rs Git - rust.git/commitdiff
Improve the error management when /proc is not mounted
authorSylvestre Ledru <sylvestre@debian.org>
Wed, 17 May 2017 13:14:30 +0000 (15:14 +0200)
committerSylvestre Ledru <sylvestre@debian.org>
Wed, 17 May 2017 13:14:30 +0000 (15:14 +0200)
This PR does two things:
* Triggers an error on GNU/Linux & Android when /proc/self/exe doesn't exist
* Handle the error properly

src/librustc/session/filesearch.rs
src/libstd/sys/unix/os.rs

index 82c2425aead734f4244f8f62a97febb54366a475..47b988a21b4c1d402628ff043556310704bd3b7c 100644 (file)
@@ -159,9 +159,14 @@ fn canonicalize(path: Option<PathBuf>) -> Option<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))
     }
 }
 
index 36928696c4059089bfffcbbca9c4e72a1e989c2a..8e41fd009be675db4954e19aae6da513f546913f 100644 (file)
@@ -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"))]