[CF] Unify implementations of _CFProcessPath. #2679
Merged
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.
Firstly,
_CFProcessPath
has no implementation for TARGET_OS_BSD. Indeed,there is no portable implementation of this action across multiple
platforms. As an initial implementation for TARGET_OS_BSD, use the
environment to help us. Some shells set the environment variable "_" to
the path used to invoke the binary. This mirrors the implementation for
TARGET_OS_OSX, so add the same conditionals on
__CFProcessIsRestricted
.Relying on the shell has drawbacks, including that the shell doesn't set
the full path to the current executable if it isn't part of the PATH
(or, of course, specified explicitly). Perhaps on some other platforms
there is some miscellaneous kernel trickery that could be done, but
let's defer that to the future and keep getenv("_") as a last resort.
Second, given that, we should bring the implementations together (like
we've done elsewhere), not to mention that
_CFProcessPath
is fundamentalto other parts of CF. This highlights the repetition in each
implementation, so here we also factor off some of it and share it
across the implementations to facilitate code reuse.