Anonymous committed 455b888

Fix pg_resetxlog to use correct path to

Since we've already chdir'd into the data directory, the file should
be referenced as just "", without prefixing the directory
path. This is harmless in the normal case where an absolute PGDATA path
is used, but quite dangerous if a relative path is specified, since the
program might then fail to notice an active postmaster.

Reported by Hari Babu. This got broken in my commit
eb5949d190e80360386113fde0f05854f0c9824d, so patch all active versions.

  • Participants
  • Parent commits 24c19e6

Comments (0)

Files changed (1)

File src/bin/pg_resetxlog/pg_resetxlog.c

 	char	   *endptr;
 	char	   *DataDir;
 	int			fd;
-	char		path[MAXPGPATH];
 	set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_resetxlog"));
 	 * Check for a postmaster lock file --- if there is one, refuse to
 	 * proceed, on grounds we might be interfering with a live installation.
-	snprintf(path, MAXPGPATH, "%s/", DataDir);
-	if ((fd = open(path, O_RDONLY, 0)) < 0)
+	if ((fd = open("", O_RDONLY, 0)) < 0)
 		if (errno != ENOENT)
-			fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"), progname, path, strerror(errno));
+			fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
+					progname, "", strerror(errno));
 		fprintf(stderr, _("%s: lock file \"%s\" exists\n"
 						  "Is a server running?  If not, delete the lock file and try again.\n"),
-				progname, path);
+				progname, "");