On Thu Feb 15 19:40:57 2024 +0000, Zebediah Figura wrote:
I took a look, but I'm not sure how helpful that is since I'll have to
still check for __linux__ anyway because I need readlink to get the actual file's path, not the symlink in procfs. Why do you need to check for __linux__ to use readlink()?
It also would incur an extra allocation that we can avoid on the
symlink's path. I don't think one small allocation is going to matter in a server call.
Because on Linux, /proc/self/fd/<fd> are symbolic links to the actual file path, so we need it to get the path of the file.
But on platforms that have F_GETPATH, the result is already the path of the file, so calling readlink on them is not just useless but also wrong, not least because it accesses the filesystem itself (rather than the stored name) which can even incur some race conditions. For example. file gets removed, a link gets placed in there to something completely unrelated, and then we read that link and whatever it points to as the file path; or something else gets mounted over and now we're reading an arbitrary link for the file path.
It's like calling readlink on Linux twice, one to get the file path and then on the file itself.