about summary refs log tree commit diff
path: root/library/std/src/sys/unix/os.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-10-05 06:56:57 +0000
committerbors <bors@rust-lang.org>2021-10-05 06:56:57 +0000
commit074f63648bd2368d5ca19aed02b5763a144e5d05 (patch)
treea39ab48aab1c9740253a22c9ac29b32953e97a45 /library/std/src/sys/unix/os.rs
parenta804c4b1123ae665a8d4f726524109c49efac5b6 (diff)
parent068683baf12f61d5ffbf8a7e4858c4e0c3320f3b (diff)
downloadrust-074f63648bd2368d5ca19aed02b5763a144e5d05.tar.gz
rust-074f63648bd2368d5ca19aed02b5763a144e5d05.zip
Auto merge of #89549 - Manishearth:rollup-mhkyc16, r=Manishearth
Rollup of 12 pull requests

Successful merges:

 - #87631 (os current_exe using same approach as linux to get always the full ab…)
 - #88234 (rustdoc-json: Don't ignore impls for primitive types)
 - #88651 (Use the 64b inner:monotonize() implementation not the 128b one for aarch64)
 - #88816 (Rustdoc migrate to table so the gui can handle >2k constants)
 - #89244 (refactor: VecDeques PairSlices fields to private)
 - #89364 (rustdoc-json: Encode json files with UTF-8)
 - #89423 (Fix ICE caused by non_exaustive_omitted_patterns struct lint)
 - #89426 (bootstrap: add config option for nix patching)
 - #89462 (haiku thread affinity build fix)
 - #89482 (Follow the diagnostic output style guide)
 - #89504 (Don't suggest replacing region with 'static in NLL)
 - #89535 (fix busted JavaScript in error index generator)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/sys/unix/os.rs')
-rw-r--r--library/std/src/sys/unix/os.rs30
1 files changed, 17 insertions, 13 deletions
diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs
index 1d5ffb07321..87893d26912 100644
--- a/library/std/src/sys/unix/os.rs
+++ b/library/std/src/sys/unix/os.rs
@@ -380,20 +380,24 @@ pub fn current_exe() -> io::Result<PathBuf> {
 
 #[cfg(any(target_os = "solaris", target_os = "illumos"))]
 pub fn current_exe() -> io::Result<PathBuf> {
-    extern "C" {
-        fn getexecname() -> *const c_char;
-    }
-    unsafe {
-        let path = getexecname();
-        if path.is_null() {
-            Err(io::Error::last_os_error())
-        } else {
-            let filename = CStr::from_ptr(path).to_bytes();
-            let path = PathBuf::from(<OsStr as OsStrExt>::from_bytes(filename));
+    if let Ok(path) = crate::fs::read_link("/proc/self/path/a.out") {
+        Ok(path)
+    } else {
+        extern "C" {
+            fn getexecname() -> *const c_char;
+        }
+        unsafe {
+            let path = getexecname();
+            if path.is_null() {
+                Err(io::Error::last_os_error())
+            } else {
+                let filename = CStr::from_ptr(path).to_bytes();
+                let path = PathBuf::from(<OsStr as OsStrExt>::from_bytes(filename));
 
-            // Prepend a current working directory to the path if
-            // it doesn't contain an absolute pathname.
-            if filename[0] == b'/' { Ok(path) } else { getcwd().map(|cwd| cwd.join(path)) }
+                // Prepend a current working directory to the path if
+                // it doesn't contain an absolute pathname.
+                if filename[0] == b'/' { Ok(path) } else { getcwd().map(|cwd| cwd.join(path)) }
+            }
         }
     }
 }