Re: [PATCH] exec: Print absolute paths for command location queries
Harald van Dijk <[email protected]> Sun, 7 Jun 2026 00:03:38 +0100
| Newsgroups | org.kernel.vger.dash |
|---|---|
| Message-ID | <[email protected]> |
On 06/06/2026 18:48, Kerin Millar wrote: > Hi Harald, > > On Sat, 6 Jun 2026, at 6:27 PM, Harald van Dijk wrote: >> I think leaving it as printing a correct relative path is better than >> printing a possibly wrong absolute path, personally. A change to print a >> correct absolute path would have my support though, for whatever that is >> worth. > > It's a good point. How about using getcwd() and printing the relative path upon failure, even if to do so would not be strictly conforming? That would be one way that sounds good to me. What I did is check if $PWD and . are the same file (using stat() and comparing dev and ino), if so using $PWD, if not fall back to getcwd(). This approach has the advantage that if $PWD is e.g. /bin where getcwd() would return /usr/bin, and both are absolute paths that refer to the same directory, the user-specified spelling of the directory is used. Another option instead of getcwd() is a hardcoded /proc/self/cwd, although it will not necessarily be portable to non-Linux systems. I do not know which of the options would be preferred for dash, but I would not personally object to any of them. Cheers, Harald van Dijk