Skip to content

Commit 614ba48

Browse files
committed
Fix pg_resetxlog to use correct path to postmaster.pid.
Since we've already chdir'd into the data directory, the file should be referenced as just "postmaster.pid", 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 eb5949d, so patch all active versions.
1 parent 875d3f3 commit 614ba48

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/bin/pg_resetxlog/pg_resetxlog.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ main(int argc, char *argv[])
9595
char *endptr3;
9696
char *DataDir;
9797
int fd;
98-
char path[MAXPGPATH];
9998

10099
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_resetxlog"));
101100

@@ -270,21 +269,20 @@ main(int argc, char *argv[])
270269
* Check for a postmaster lock file --- if there is one, refuse to
271270
* proceed, on grounds we might be interfering with a live installation.
272271
*/
273-
snprintf(path, MAXPGPATH, "%s/postmaster.pid", DataDir);
274-
275-
if ((fd = open(path, O_RDONLY, 0)) < 0)
272+
if ((fd = open("postmaster.pid", O_RDONLY, 0)) < 0)
276273
{
277274
if (errno != ENOENT)
278275
{
279-
fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"), progname, path, strerror(errno));
276+
fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
277+
progname, "postmaster.pid", strerror(errno));
280278
exit(1);
281279
}
282280
}
283281
else
284282
{
285283
fprintf(stderr, _("%s: lock file \"%s\" exists\n"
286284
"Is a server running? If not, delete the lock file and try again.\n"),
287-
progname, path);
285+
progname, "postmaster.pid");
288286
exit(1);
289287
}
290288

0 commit comments

Comments
 (0)