Fix error message on short read of pg_control

Instead of saying "error: success", indicate that we got a working read
but it was too short.
This commit is contained in:
Magnus Hagander 2018-05-18 17:53:17 +02:00
parent 6d7629094a
commit 714d8e5fa1

View File

@ -4258,6 +4258,7 @@ ReadControlFile(void)
{ {
pg_crc32c crc; pg_crc32c crc;
int fd; int fd;
int r;
/* /*
* Read data... * Read data...
@ -4271,10 +4272,17 @@ ReadControlFile(void)
errmsg("could not open control file \"%s\": %m", errmsg("could not open control file \"%s\": %m",
XLOG_CONTROL_FILE))); XLOG_CONTROL_FILE)));
if (read(fd, ControlFile, sizeof(ControlFileData)) != sizeof(ControlFileData)) r = read(fd, ControlFile, sizeof(ControlFileData));
ereport(PANIC, if (r != sizeof(ControlFileData))
(errcode_for_file_access(), {
errmsg("could not read from control file: %m"))); 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); close(fd);