Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1exFr7-0000cw-VA for pgsql-bugs@arkaria.postgresql.org; Sat, 17 Mar 2018 17:42:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1exFr6-00037w-7P for pgsql-bugs@arkaria.postgresql.org; Sat, 17 Mar 2018 17:42:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1exFr6-00037m-0w for pgsql-bugs@lists.postgresql.org; Sat, 17 Mar 2018 17:42:56 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1exFr2-0005Jy-Lo for pgsql-bugs@lists.postgresql.org; Sat, 17 Mar 2018 17:42:55 +0000 Received: from [192.168.127.1] (port=52230 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1exFqz-000NYJ-DC; Sat, 17 Mar 2018 17:42:49 +0000 Received: from [127.0.0.1] (port=38898 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1exFqy-000ETX-7p; Sat, 17 Mar 2018 17:42:48 +0000 From: Andrew Gierth To: Tom Lane Cc: petar@smokva.net, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15120: use of getcwd(3)/chdir(2) during path resolution (exec.c) In-Reply-To: <18476.1521304133@sss.pgh.pa.us> (Tom Lane's message of "Sat, 17 Mar 2018 12:28:53 -0400") Message-ID: <87in9uhbco.fsf@news-spur.riddles.org.uk> References: <152130268473.1317.3689189784729884454@wrigleys.postgresql.org> <18476.1521304133@sss.pgh.pa.us> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Sat, 17 Mar 2018 17:42:46 +0000 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Tom" == Tom Lane 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)