about summary refs log tree commit diff
path: root/library/std/src/sys
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2021-10-04 23:56:15 -0700
committerGitHub <noreply@github.com>2021-10-04 23:56:15 -0700
commit0fb01224dd6d1966ca4f64416e092243ae19ec84 (patch)
tree427b8564895ed844636187121b0e112750f3ad49 /library/std/src/sys
parenta804c4b1123ae665a8d4f726524109c49efac5b6 (diff)
parentcb4519e59c75b848e808a28f2046c8bc2f91b943 (diff)
Rollup merge of #87631 - :solarish_upd_fs, r=joshtriplett
os current_exe using same approach as linux to get always the full ab…

…solute path
Diffstat (limited to 'library/std/src/sys')
-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)) }
+            }
         }
     }
 }