From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Fri, 24 Dec 2004 16:55:43 +0000 (+0000)
Subject: Remove 'optimization' to skip resolve_symlinks() when the found
X-Git-Tag: REL8_0_0RC3~32
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f0c08ae7c95bf71cabcae351825b58e528a68b77;p=postgresql

Remove 'optimization' to skip resolve_symlinks() when the found
executable file isn't itself a symlink.  We still need to run the
algorithm so that any directory symlinks in the path to the
executable are replaced by a true path.  Noticed this on seeing
pg_config give me a completely wrong answer for --pkglibdir when
I called it through a symlink to the installation bindir.
---

diff --git a/src/port/exec.c b/src/port/exec.c
index 62a833cb85..c5905129f5 100644
--- a/src/port/exec.c
+++ b/src/port/exec.c
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/port/exec.c,v 1.34 2004/12/20 17:40:59 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/port/exec.c,v 1.35 2004/12/24 16:55:43 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -272,8 +272,7 @@ find_my_exec(const char *argv0, char *retpath)
 /*
  * resolve_symlinks - resolve symlinks to the underlying file
  *
- * If path does not point to a symlink, leave it alone.  If it does,
- * replace it by the absolute path to the referenced file.
+ * Replace "path" by the absolute path to the referenced file.
  *
  * Returns 0 if OK, -1 if error.
  *
@@ -290,17 +289,17 @@ resolve_symlinks(char *path)
 				link_buf[MAXPGPATH];
 	char	   *fname;
 
-	/* Quick out if it's not a symlink */
-	if (lstat(path, &buf) < 0 ||
-		(buf.st_mode & S_IFMT) != S_IFLNK)
-		return 0;
-
 	/*
 	 * To resolve a symlink properly, we have to chdir into its directory
 	 * and then chdir to where the symlink points; otherwise we may fail to
 	 * resolve relative links correctly (consider cases involving mount
 	 * points, for example).  After following the final symlink, we use
 	 * getcwd() to figure out where the heck we're at.
+	 *
+	 * One might think we could skip all this if path doesn't point to a
+	 * symlink to start with, but that's wrong.  We also want to get rid
+	 * of any directory symlinks that are present in the given path.
+	 * We expect getcwd() to give us an accurate, symlink-free path.
 	 */
 	if (!getcwd(orig_wd, MAXPGPATH))
 	{