Skip to content

Commit 31ae4f1

Browse files
committed
On DragonFly use procfs for self_exe_name()
Using /proc/curproc/file does not resolve mount-points as sysctl(3) with KERN_PROC_PATHNAME does, which gave back paths containing colons like /pfs/@@-1:00004/usr/bin. This led to problems when joining paths based on it.
1 parent 6131df6 commit 31ae4f1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/libstd/os.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ pub fn dll_filename(base: &str) -> String {
665665
/// ```
666666
pub fn self_exe_name() -> Option<Path> {
667667

668-
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
668+
#[cfg(target_os = "freebsd")]
669669
fn load_self() -> Option<Vec<u8>> {
670670
unsafe {
671671
use libc::funcs::bsd44::*;
@@ -691,6 +691,16 @@ pub fn self_exe_name() -> Option<Path> {
691691
}
692692
}
693693

694+
#[cfg(target_os = "dragonfly")]
695+
fn load_self() -> Option<Vec<u8>> {
696+
use std::io;
697+
698+
match io::fs::readlink(&Path::new("/proc/curproc/file")) {
699+
Ok(path) => Some(path.into_vec()),
700+
Err(..) => None
701+
}
702+
}
703+
694704
#[cfg(any(target_os = "linux", target_os = "android"))]
695705
fn load_self() -> Option<Vec<u8>> {
696706
use std::io;

0 commit comments

Comments
 (0)