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 1exGDl-0001qi-9E for pgsql-bugs@arkaria.postgresql.org; Sat, 17 Mar 2018 18:06:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1exGDk-0003yQ-9R for pgsql-bugs@arkaria.postgresql.org; Sat, 17 Mar 2018 18:06:20 +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 1exGDk-0003yG-2k for pgsql-bugs@lists.postgresql.org; Sat, 17 Mar 2018 18:06:20 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1exGDh-0005sV-Ef for pgsql-bugs@lists.postgresql.org; Sat, 17 Mar 2018 18:06:19 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w2HI6Em5007609; Sat, 17 Mar 2018 14:06:14 -0400 From: Tom Lane To: Andrew Gierth 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: <87in9uhbco.fsf@news-spur.riddles.org.uk> References: <152130268473.1317.3689189784729884454@wrigleys.postgresql.org> <18476.1521304133@sss.pgh.pa.us> <87in9uhbco.fsf@news-spur.riddles.org.uk> Comments: In-reply-to Andrew Gierth message dated "Sat, 17 Mar 2018 17:42:46 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <7606.1521309974.1@sss.pgh.pa.us> Date: Sat, 17 Mar 2018 14:06:14 -0400 Message-ID: <7607.1521309974@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andrew Gierth writes: > "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? Um ... AFAICS, openat() just opens a file, it doesn't give back a resolved path. Did you mean readlinkat()? In any case, we'd still need to support logic that doesn't rely on non-portable functions. The (vague) idea I had was to try a little harder to build absolute paths for ourselves instead of letting the system do it. I believe for instance that canonicalize_path() has more smarts now about shortening paths like /foo/bar/baz/../../quux than it did when these functions were written, so we might be able to rely on just concatenating paths and then canonicalizing the result. (OTOH, I think there are filesystems where this wouldn't necessarily yield a nice answer, due to multiple mounts and suchlike.) regards, tom lane