]> granicus.if.org Git - postgresql/commitdiff
Fix error message on short read of pg_control
authorMagnus Hagander <magnus@hagander.net>
Fri, 18 May 2018 15:53:17 +0000 (17:53 +0200)
committerMagnus Hagander <magnus@hagander.net>
Fri, 18 May 2018 15:53:17 +0000 (17:53 +0200)
Instead of saying "error: success", indicate that we got a working read
but it was too short.

src/backend/access/transam/xlog.c

index 527ce760e490c758545df45739903ef8150d497e..5d845a817897b04a6218ea72ee5ba3655628eb09 100644 (file)
@@ -4258,6 +4258,7 @@ ReadControlFile(void)
 {
        pg_crc32c       crc;
        int                     fd;
+       int                     r;
 
        /*
         * Read data...
@@ -4271,10 +4272,17 @@ ReadControlFile(void)
                                 errmsg("could not open control file \"%s\": %m",
                                                XLOG_CONTROL_FILE)));
 
-       if (read(fd, ControlFile, sizeof(ControlFileData)) != sizeof(ControlFileData))
-               ereport(PANIC,
-                               (errcode_for_file_access(),
-                                errmsg("could not read from control file: %m")));
+       r = read(fd, ControlFile, sizeof(ControlFileData));
+       if (r != sizeof(ControlFileData))
+       {
+               if (r < 0)
+                       ereport(PANIC,
+                                       (errcode_for_file_access(),
+                                        errmsg("could not read from control file: %m")));
+               else
+                       ereport(PANIC,
+                                        (errmsg("could not read from control file: read %d bytes, expected %d", r, (int) sizeof(ControlFileData))));
+       }
 
        close(fd);