-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Inconsistent current_exe behavior for symlinks on different platforms #43617
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
Comments
I suspect this will have to be fixed in documentation (probably by just being more vague about what different platforms return) since I'm not sure there's a way to get what you want in Linux:
I note that the busybox docker container uses hardlinks in Putting aside |
Behavior on Windows is similar to the behavior on OS X. It calls
|
- Update example in ‘security’ section to use hard links, like the linked securityvulns.com example. - Weaken language on symbolic links – indicate behavior is platform-specific Fixes rust-lang#43617.
opened a pr for this: #46987 |
…ietMisdreavus Minor rewrite of env::current_exe docs; clarify symlinks. - Update example in ‘security’ section to use hard links, like the linked securityvulns.com example. - Weaken language on symbolic links – indicate behavior is platform-specific Fixes rust-lang#43617.
## [why] `std::env::current_exe()` has platform dependent behavior and will often not return a symlink name when executed via symlink. ... fallback to `std::env::current_ext()` if args are missing or empty. - ref: <rust-lang/rust#43617>
## [why] `std::env::current_exe()` has platform dependent behavior and will often return the target binary, not the symlink name, when the binary is executed via symlink. So, to support symlinking, the first (0th) arg from `std::env::args()` is used, when possible with fallback to `std::env::current_ext()` if args are missing or empty. - ref: <rust-lang/rust#43617>
## [why] `std::env::current_exe()` has platform dependent behavior and will often return the target binary, not the symlink name, when the binary is executed via symlink. So, to support symlinking, the first (0th) arg from `std::env::args()` is used, when possible, with fallback to `std::env::current_ext()` if args are missing or empty. - ref: <rust-lang/rust#43617>
## [why] `std::env::current_exe()` has platform dependent behavior and will often return the target binary, not the symlink name, when the binary is executed via symlink. So, to support symlinking, the first (0th) arg from `std::env::args()` is used, when possible, with fallback to `std::env::current_ext()` if args are missing or empty. - ref: <rust-lang/rust#43617>
…re possible ## [why] `std::env::current_exe()` has platform dependent behavior and will often return the target binary, not the symlink name, when the binary is executed via symlink. So, to support symlinking, the first (0th) arg from `std::env::args()` is used, when possible, with fallback to `std::env::current_ext()` if args are missing or empty. - ref: <rust-lang/rust#43617>
…re possible ## [why] `std::env::current_exe()` has platform dependent behavior and will often return the target binary, not the symlink name, when the binary is executed via symlink. So, to support symlinking, the first (0th) arg from `std::env::args()` is used, when possible, with fallback to `std::env::current_ext()` if args are missing or empty. - ref: <rust-lang/rust#43617>
…re possible ## [why] `std::env::current_exe()` has platform dependent behavior and will often return the target binary, not the symlink name, when the binary is executed via symlink. So, to support symlinking, the first (0th) arg from `std::env::args()` is used, when possible, with fallback to `std::env::current_ext()` if args are missing or empty. - ref: <rust-lang/rust#43617>
…re possible ## [why] `std::env::current_exe()` has platform dependent behavior and will often return the target binary, not the symlink name, when the binary is executed via symlink. So, to support symlinking, the first (0th) arg from `std::env::args()` is used, when possible, with fallback to `std::env::current_ext()` if args are missing or empty. - ref: <rust-lang/rust#43617>
…re possible ## [why] `std::env::current_exe()` has platform dependent behavior and will often return the target binary, not the symlink name, when the binary is executed via symlink. So, to support symlinking, the first (0th) arg from `std::env::args()` is used, when possible, with fallback to `std::env::current_ext()` if args are missing or empty. - ref: <rust-lang/rust#43617>
…re possible ## [why] `std::env::current_exe()` has platform dependent behavior and will often return the target binary, not the symlink name, when the binary is executed via symlink. So, to support symlinking, the first (0th) arg from `std::env::args()` is used, when possible, with fallback to `std::env::current_ext()` if args are missing or empty. - ref: <rust-lang/rust#43617>
Background
I was attempting to use
std::env::current_exe()
to figure out how my program was invoked so I could respond with convenience code paths (analogous to howgpgv
is basically a shortcut/alias forgpg --verify
) when I noticed inconsistent behavior between OS X and Linux when the program was invoked via a symbolic link.Steps to Reproduce
test.rs
For convenience I have bundled these in a repo: jeffweiss/rust-current_exe
Rust Version
rustc 1.19.0 (0ade339 2017-07-17)
Expected Behavior
On all platforms, I would expect to get:
Actual Behavior
On Mac OS X, I get:
On Linux, I get:
Related Documentation
The documentation for
std::env::current_exe
implies that if you runcurrent_exe
from the symlink, you'll get the name of the symlink, not the dereferenced target of the symlink; however, the documentation's example does not actually include a symbolic link (ln -s
), but rather a hard link (ln
).The text was updated successfully, but these errors were encountered: