8000 Fix pg_resetxlog to use correct path to postmaster.pid. · micdev42/postgres@336bc0d · GitHub
[go: up one dir, main page]

Skip to content

Commit 336bc0d

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 3352e25 commit 336bc0d

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
@@ -87,7 +87,6 @@ main(int argc, char *argv[])
8787
char *endptr3;
8888
char *DataDir;
8989
int fd;
90-
char path[MAXPGPATH];
9190

9291
set_pglocale_pgservice(argv[0], "pg_resetxlog");
9392

@@ -262,21 +261,20 @@ main(int argc, char *argv[])
262261
* Check for a postmaster lock file --- if there is one, refuse to
263262
* proceed, on grounds we might be interfering with a live installation.
264263
*/
265-
snprintf(path, MAXPGPATH, "%s/postmaster.pid", DataDir);
266-
267-
if ((fd = open(path, O_RDONLY, 0)) < 0)
264+
if ((fd = open("postmaster.pid", O_RDONLY, 0)) < 0)
268265
{
269266
if (errno != ENOENT)
270267
{
271-
fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"), progname, path, strerror(errno));
268+
fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
269+
progname, "postmaster.pid", strerror(errno));
272270
exit(1);
273271
}
274272
}
275273
else
276274
{
277275
fprintf(stderr, _("%s: lock file \"%s\" exists\n"
278276
"Is a server running? If not, delete the lock file and try again.\n"),
279-
progname, path);
277+
progname, "postmaster.pid");
280278
exit(1);
281279
}
282280

0 commit comments

Comments
 (0)
0