Add argv[0] fallback for current_exe() on Linux when /proc is unavailable#153603
Open
Ecordonnier wants to merge 1 commit intorust-lang:mainfrom
Open
Add argv[0] fallback for current_exe() on Linux when /proc is unavailable#153603Ecordonnier wants to merge 1 commit intorust-lang:mainfrom
Ecordonnier wants to merge 1 commit intorust-lang:mainfrom
Conversation
Collaborator
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
3f3743c to
681b21f
Compare
This comment has been minimized.
This comment has been minimized.
…able When /proc/self/exe is not accessible (e.g., in containers with masked /proc, chroot environments, or systemd services with ProtectProc=invisible), current_exe() will now fall back to parsing argv[0] and searching PATH. This brings the Linux implementation in line with existing Rust stdlib patterns on Fuchsia, Solaris/illumos, and AIX, which also use argv[0] when direct kernel APIs are unavailable. Fallback strategy: 1. Try /proc/self/exe (fast path, existing behavior) 2. On NotFound error, retrieve argv[0] from env::args() 3. If argv[0] is absolute, use it directly 4. If argv[0] contains '/', resolve it as relative path against getcwd() 5. Otherwise, search PATH for the executable (checking execute permissions) 6. Return NotFound error if executable not found in PATH This handles all common invocation patterns: - Absolute path: `/usr/bin/program` - Relative path: `./program` or `../bin/program` - PATH lookup: `program` (searches directories in PATH) This maintains backward compatibility: behavior is unchanged when /proc is accessible. Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
681b21f to
23dfde3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When /proc/self/exe is not accessible (e.g., in containers with masked /proc, chroot environments, or systemd services with ProtectProc=invisible), current_exe() will now fall back to parsing argv[0] and searching PATH.
This brings the Linux implementation in line with existing Rust stdlib patterns on Fuchsia, Solaris/illumos, and AIX, which also use argv[0] when direct kernel APIs are unavailable.
Fallback strategy:
This handles all common invocation patterns:
/usr/bin/program./programor../bin/programprogram(searches directories in PATH)This maintains backward compatibility: behavior is unchanged when /proc is accessible.
Fixes #46090