You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Of course, I will rewrite this code to be C compliant once the pr will be opened. OpenBSD has no official API for getting the current exe path, and I don't know if it ever did, it very well may have when the procfs was available, but i wasn't an OpenBSD user when that was still available to the OS. This is pretty much the best we can do without an official API.
Tbh I hate the complexities of that code, the hoops we'd have to jump through.
Because it relies on $PATH and the working directory, you need to jump through hoops to get the original values of those. But even that isn't actually guaranteed to be correct!
Because what you need is the $PATH and cwd of fish's parent process, at the time it started fish. And that is iff it decided to not play games with argv[0] - like call us as -fish.
So I'm tempted to just declare that we'll be printing "fish" on OpenBSD until they grow a feature that allows us to actually be correct.
Honestly IMO if we need to do any more work than take advantage of the platform-specific API to get the executable path, I don't think we should go so far as trying to derive it by heroic means.
I admittedly don't fully understand where the problem is.
Another option instead of using argv[0] would be to use getprogname() although that would break with a relative path to fish in some cases. Not many people would use a relative path to fish, most people would would run based on the filename spec without the directory spec. Thus, the using $PATH + getprogname might be good enough.
It would not. In fact that would barely be better than what we have now.
the compare a few stat structure members with the stat structure returned by opening the path the function guessed points to the current executable
Please don't. That just adds more guesswork and complication, for unclear gain.
Here's what we can do:
We can resolve the executable path once, at startup
If we do that at startup, we can check for it in $PWD and/or $PATH at that time - just do it before we read our config and it's fine
If it doesn't resolve, return "fish" so people using status fish-path could conceivably find fish via $PATH at that time
(optional) As one special case, handle -fish like fish.
I'm like a few days late on this, but I'm happy with how the NetBSD one went. It just needed different sysctl parameters to get the executable path for the current process. My understanding was there was some discussion of trying to do a normalization step to remove redundancies like symlinks, or '..' appearing in the middle - and this was (IMO) correctly abandoned because we still got an actual path to the executable. What is the specific issue on OpenBSD?
Sorry for asking this all dumbed up but I tried to check the commits at one point a couple days ago on one of these and the branch was deleted, and I'm seeing these links to other projects - please sum it up.
I'm probably going to need to install OpenBSD again to figure this out then, because I just don't know what you mean. How do PWD, PATH, argv[0] relate to what the kernel can tell us?
I read the docs for none() and it only returns true of all bits are zero.
"none()" is part of our maybe_t implementation - basically a backport of std::optional.
In essence you'd use it like
auto path = path_get_path(wargv[0], nullptr);
if (path) {
wcstring actual_path = *path;
}
This is because maybe_t overloads operator bool(), so you can use it like it's a null pointer - with the exception that maybe_t<wcstring> doesn't work in place of a wcstring like a NULL would in place of a wchar_t*.
Activity
faho commentedon Jul 24, 2022
You'll want to look through our codebase, because we do of course have helpers to find an executable in $PATH, or to add $PWD to a path.
That should make this quite a bit simpler.
faho commentedon Jul 24, 2022
Tbh I hate the complexities of that code, the hoops we'd have to jump through.
Because it relies on $PATH and the working directory, you need to jump through hoops to get the original values of those. But even that isn't actually guaranteed to be correct!
Because what you need is the $PATH and cwd of fish's parent process, at the time it started fish. And that is iff it decided to not play games with argv[0] - like call us as
-fish.So I'm tempted to just declare that we'll be printing "fish" on OpenBSD until they grow a feature that allows us to actually be correct.
floam commentedon Jul 25, 2022
I'm surprised the OpenBSD kernel developers do not provide a way to do this, considering their security stance and repute.
floam commentedon Jul 25, 2022
I read this a bit: ziglang/zig#6718
Honestly IMO if we need to do any more work than take advantage of the platform-specific API to get the executable path, I don't think we should go so far as trying to derive it by heroic means.
I admittedly don't fully understand where the problem is.
faho commentedon Jul 25, 2022
It would not. In fact that would barely be better than what we have now.
Please don't. That just adds more guesswork and complication, for unclear gain.
Here's what we can do:
status fish-pathcould conceivably find fish via $PATH at that time-fishlikefish.floam commentedon Jul 25, 2022
I'm like a few days late on this, but I'm happy with how the NetBSD one went. It just needed different sysctl parameters to get the executable path for the current process. My understanding was there was some discussion of trying to do a normalization step to remove redundancies like symlinks, or '..' appearing in the middle - and this was (IMO) correctly abandoned because we still got an actual path to the executable. What is the specific issue on OpenBSD?
Sorry for asking this all dumbed up but I tried to check the commits at one point a couple days ago on one of these and the branch was deleted, and I'm seeing these links to other projects - please sum it up.
floam commentedon Jul 25, 2022
I'm probably going to need to install OpenBSD again to figure this out then, because I just don't know what you mean. How do PWD, PATH, argv[0] relate to what the kernel can tell us?
floam commentedon Jul 25, 2022
We can get perhaps the parent directory or something?
12 remaining items
faho commentedon Jul 26, 2022
"none()" is part of our maybe_t implementation - basically a backport of std::optional.
In essence you'd use it like
This is because maybe_t overloads
operator bool(), so you can use it like it's a null pointer - with the exception thatmaybe_t<wcstring>doesn't work in place of awcstringlike a NULL would in place of awchar_t*.faho commentedon Jul 27, 2022
In terms of complexity that seems acceptable. If it works, we can use it.
brad0 commentedon Sep 4, 2026
Just FYI OpenBSD now has getexecpath() to deal with this.
Darkshadow2 commentedon Sep 4, 2026
According to the
HISTORYsection on the manpage getexecpath is being added to OpenBSD 8.0, which isn't out yetbrad0 commentedon Sep 13, 2026
Snapshots are available. 8.0 final will be out in a few weeks.
Use getexecpath() to find the executable path on OpenBSD