Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 455b888

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 24c19e6 commit 455b888

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
@@ -91,7 +91,6 @@ main(int argc, char *argv[])
9191
char *endptr;
9292
char *DataDir;
9393
int fd;
94-
char path[MAXPGPATH];
9594

9695
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_resetxlog"));
9796

@@ -252,21 +251,20 @@ main(int argc, char *argv[])
252251
* Check for a postmaster lock file --- if there is one, refuse to
253252
* proceed, on grounds we might be interfering with a live installation.
254253
*/
255-
snprintf(path, MAXPGPATH, "%s/postmaster.pid", DataDir);
256-
257-
if ((fd = open(path, O_RDONLY, 0)) < 0)
254+
if ((fd = open("postmaster.pid", O_RDONLY, 0)) < 0)
258255
{
259256
if (errno != ENOENT)
260257
{
261-
fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"), progname, path, strerror(errno));
258+
fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
259+
progname, "postmaster.pid", strerror(errno));
262260
exit(1);
263261
}
264262
}
265263
else
266264
{
267265
fprintf(stderr, _("%s: lock file \"%s\" exists\n"
268266
"Is a server running? If not, delete the lock file and try again.\n"),
269-
progname, path);
267+
progname, "postmaster.pid");
270268
exit(1);
271269
}
272270

0 commit comments

Comments
 (0)