On Fri Feb 16 18:54:57 2024 +0000, Zebediah Figura wrote:
How do you want to avoid checking for linux here? If we call readlink
unconditionally, then we'll end up with readlink("/path/to/file") on other platforms which is the thing I was mentioning being wrong. What I'm trying to ask is, why would this be wrong? Why is it important that we don't use readlink() on this path?
The job of this function is to retrieve the file's path and filename for anonymous fds (such as redirected unix outputs). It shouldn't access the underlying filesystem at all: that's obviously wrong, since it shouldn't depend on when it's called, nor if the file was deleted or not (it's not the purpose of this function to deal with that).
For example, in theory, the file could get removed after retrieving its path (via F_GETPATH) and a symlink placed in place of it, then readlink would access that symlink and dereference it… Whether the rest of the code deals with such race conditions is another point, but I don't see why this function should have to concern itself with it, or access the filesystem at all? It's like needless corner cases to worry about.