On Thu Feb 15 19:40:57 2024 +0000, Gabriel Ivăncescu wrote:
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.
Well, the race condition exists as soon as you're calling readlink() even once, and I don't think they're meaningful anyway (what's the application going to do with this information?)
But I also don't understand why returning a symlink instead of the target is important?