Skip to content

Conversation

@michael-yuji
Copy link
Member

Currently executable importing Foundation may crash when launched with certain shell as a platform specific way to get the path of the process's executable is not defined. This PR implements this missing piece to fetch the process path via sysctl

// in case for whatever reason the path is > PATH_MAX
if (sysctl_ret == -1 && errno == ENOMEM) {
// get size needed
sysctl_ret = sysctl(mib, 4, NULL, &len, NULL, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not do this unconditionally to compute the required length?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we should almost never the case when exec path is > PATH_MAX, so we can save an extra syscall in most cases. (In fact, I'm not sure if it's even possible on generic FreeBSD, but there are many FreeBSD variants floating around...)

@jakepetroules jakepetroules moved this from Done to In Progress in Swift on FreeBSD Mar 18, 2025
@grynspan
Copy link
Contributor

Swift Testing has an implementation of this that may be useful. Given that both Swift Testing and Foundation need this information, it may make sense to add it to the stdlib.

@parkera
Copy link
Contributor

parkera commented Mar 25, 2025

@swift-ci test

@michael-yuji michael-yuji merged commit c23cc23 into swiftlang:main Apr 9, 2025
2 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Swift on FreeBSD Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants