New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OpenBSD: current_exe() fails when bin resolved through $PATH #60560
Comments
Note that the code in rust upstream silently defaults to a wrong path (simply the program name in the current working directory), while openbsd downstream applies a patch to make this fail explicitly: $OpenBSD: patch-src_libstd_sys_unix_os_rs,v 1.10 2019/03/11 19:13:40 semarie Exp $
argv0 isn't suitable as current_exe() in all cases.
Index: src/libstd/sys/unix/os.rs
--- src/libstd/sys/unix/os.rs.orig
+++ src/libstd/sys/unix/os.rs
@@ -273,13 +273,14 @@ pub fn current_exe() -> io::Result<PathBuf> {
argv.set_len(argv_len as usize);
if argv[0].is_null() {
return Err(io::Error::new(io::ErrorKind::Other,
- "no current exe available"))
+ "no current exe available (null)"))
}
let argv0 = CStr::from_ptr(argv[0]).to_bytes();
if argv0[0] == b'.' || argv0.iter().any(|b| *b == b'/') {
::fs::canonicalize(OsStr::from_bytes(argv0))
} else {
- Ok(PathBuf::from(OsStr::from_bytes(argv0)))
+ Err(io::Error::new(io::ErrorKind::Other,
+ "no current exe available (short)"))
}
}
} Unfortunately this patch doesn't give me the real path either. |
Looks like the person who added this patch is on GitHub. @semarie can you share some context for why this patch is necessary on OpenBSD? |
under OpenBSD, you have no standard way to retreive the path of the running executable. basically it means the patch on the OpenBSD ports is here to hard fail instead of silenciously use a potential wrong path. |
OpenBSD does not offer a standard way to retrieve the path of the running executable. This means that env::current_exe() cannot return anything useful when bupstash is resolved through $PATH resulting in a hard fail (rust-lang/rust#60560): ``` $ bupstash version bupstash-0.6.3 $ export BUPSTASH_REPOSITORY=/tmp/xxx $ rm -rf $BUPSTASH_REPOSITORY; bupstash init; echo $? bupstash init: no current exe available (short) 1 $ rm -rf $BUPSTASH_REPOSITORY; ./bupstash init; echo $? 0 ``` Instead use progname via std::env::args() on OpenBSD: ``` $ export BUPSTASH_REPOSITORY=/tmp/xxx $ rm -rf $BUPSTASH_REPOSITORY; bupstash init; echo $? 0 $ rm -rf $BUPSTASH_REPOSITORY; ./bupstash init; echo $? 0 ```
OpenBSD does not offer a standard way to retrieve the path of the running executable. This means that env::current_exe() cannot return anything useful when bupstash is resolved through $PATH resulting in a hard fail (rust-lang/rust#60560): ``` $ bupstash version bupstash-0.6.3 $ export BUPSTASH_REPOSITORY=/tmp/xxx $ rm -rf $BUPSTASH_REPOSITORY; bupstash init; echo $? bupstash init: no current exe available (short) 1 $ rm -rf $BUPSTASH_REPOSITORY; ./bupstash init; echo $? 0 ``` Instead use progname via std::env::args() on OpenBSD: ``` $ export BUPSTASH_REPOSITORY=/tmp/xxx $ rm -rf $BUPSTASH_REPOSITORY; bupstash init; echo $? 0 $ rm -rf $BUPSTASH_REPOSITORY; ./bupstash init; echo $? 0 ```
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
The text was updated successfully, but these errors were encountered: