]> granicus.if.org Git - postgresql/commitdiff
Report postmaster.pid file as empty if it is empty, rather than
authorBruce Momjian <bruce@momjian.us>
Wed, 29 Aug 2012 21:05:22 +0000 (17:05 -0400)
committerBruce Momjian <bruce@momjian.us>
Wed, 29 Aug 2012 21:05:22 +0000 (17:05 -0400)
reporting in contains invalid data.

src/backend/utils/init/miscinit.c
src/bin/pg_ctl/pg_ctl.c

index 775d71f56c57f4c954054653b454270427fc5395..9a0f92c268201103c3eb605db11d0129b97180f2 100644 (file)
@@ -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);
 
index af8d8b28e690ce37aa3a8565bcbe4f3e4ffa62a9..81ba39ec409370c8da5979cce97129f584cf82e4 100644 (file)
@@ -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);