summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian2012-08-29 21:05:22 +0000
committerBruce Momjian2012-08-29 21:05:22 +0000
commit3825963e7fbaa8dbc462d4f5286ff6149f4703dd (patch)
tree836f64e993b2e4ddb5f855381c4b512183e8dff1
parentc82dedb7a8a953785f24a3b10de376760d60c24c (diff)
Report postmaster.pid file as empty if it is empty, rather than
reporting in contains invalid data.
-rw-r--r--src/backend/utils/init/miscinit.c8
-rw-r--r--src/bin/pg_ctl/pg_ctl.c9
2 files changed, 15 insertions, 2 deletions
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index 775d71f56c5..9a0f92c2682 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -766,6 +766,14 @@ CreateLockFile(const char *filename, bool amPostmaster,
filename)));
close(fd);
+ if (len == 0)
+ {
+ ereport(FATAL,
+ (errcode(ERRCODE_LOCK_FILE_EXISTS),
+ errmsg("lock file \"%s\" is empty", filename),
+ errhint("Either another server is starting, or the lock file is the remnant of a previous server startup crash.")));
+ }
+
buffer[len] = '\0';
encoded_pid = atoi(buffer);
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index af8d8b28e69..81ba39ec409 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -292,8 +292,13 @@ get_pgpid(void)
}
if (fscanf(pidf, "%ld", &pid) != 1)
{
- write_stderr(_("%s: invalid data in PID file \"%s\"\n"),
- progname, pid_file);
+ /* Is the file empty? */
+ if (ftell(pidf) == 0 && feof(pidf))
+ write_stderr(_("%s: the PID file \"%s\" is empty\n"),
+ progname, pid_file);
+ else
+ write_stderr(_("%s: invalid data in PID file \"%s\"\n"),
+ progname, pid_file);
exit(1);
}
fclose(pidf);