>>>>> "Tom" == Tom Lane <tgl@sss.pgh.pa.us> writes:
Tom> ... I find that quite an unacceptable answer. We need to resolve
Tom> the symlink correctly, or we risk malfunctioning later, for the
Tom> reasons recited in the comment for find_my_exec().
On systems with openat(), would it not be possible to resolve symlinks
without ever needing chdir?
Tom> I think your example of "sudo /usr/bin/pg_ctl" is pretty
Tom> artificial; who'd bother spelling that out?
Not necessarily exactly like that, but we do occasionally get this issue
coming up on the IRC channel.
Tom> While I've not thought about it very hard, it might be possible to
Tom> rewrite find_my_exec() and resolve_symlinks() "from the ground up"
Tom> so that they don't do getcwd() except in cases where there's
Tom> really no alternative, such as the executable having been invoked
Tom> using a relative path.
I think getcwd is avoidable even then, if openat() etc. are available.
--
Andrew (irc:RhodiumToad)