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:19 +02:00
parent 62e0020ad4
commit b5f096d50b

View File

@ -4471,6 +4471,7 @@ ReadControlFile(void)
{
pg_crc32 crc;
int fd;
int r;
/*
* Read data...
@ -4484,10 +4485,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);