-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
C-bugCategory: This is a bug.Category: This is a bug.O-openbsdOperating system: OpenBSDOperating system: OpenBSDT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
I've noticed std::env::current_exe()
on openbsd depends on argv[0], which means the resolution only works if the binary was started with a relative or absolute path, but not when it was resolved by the shell using $PATH.
rust/src/libstd/sys/unix/os.rs
Lines 260 to 286 in 9ebf478
#[cfg(any(target_os = "bitrig", target_os = "openbsd"))] | |
pub fn current_exe() -> io::Result<PathBuf> { | |
unsafe { | |
let mut mib = [libc::CTL_KERN, | |
libc::KERN_PROC_ARGS, | |
libc::getpid(), | |
libc::KERN_PROC_ARGV]; | |
let mib = mib.as_mut_ptr(); | |
let mut argv_len = 0; | |
cvt(libc::sysctl(mib, 4, ptr::null_mut(), &mut argv_len, | |
ptr::null_mut(), 0))?; | |
let mut argv = Vec::<*const libc::c_char>::with_capacity(argv_len as usize); | |
cvt(libc::sysctl(mib, 4, argv.as_mut_ptr() as *mut _, | |
&mut argv_len, ptr::null_mut(), 0))?; | |
argv.set_len(argv_len as usize); | |
if argv[0].is_null() { | |
return Err(io::Error::new(io::ErrorKind::Other, | |
"no current exe available")) | |
} | |
let argv0 = CStr::from_ptr(argv[0]).to_bytes(); | |
if argv0[0] == b'.' || argv0.iter().any(|b| *b == b'/') { | |
crate::fs::canonicalize(OsStr::from_bytes(argv0)) | |
} else { | |
Ok(PathBuf::from(OsStr::from_bytes(argv0))) | |
} | |
} | |
} |
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.O-openbsdOperating system: OpenBSDOperating system: OpenBSDT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.