Skip to content

Commit 048caa5

Browse files
committed
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.
1 parent bc711be commit 048caa5

File tree

1 file changed

+12
-4
lines changed
  • src/backend/access/transam

1 file changed

+12
-4
lines changed

src/backend/access/transam/xlog.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,6 +3582,7 @@ ReadControlFile(void)
35823582
{
35833583
pg_crc32 crc;
35843584
int fd;
3585+
int r;
35853586

35863587
/*
35873588
* Read data...
@@ -3595,10 +3596,17 @@ ReadControlFile(void)
35953596
errmsg("could not open control file \"%s\": %m",
35963597
XLOG_CONTROL_FILE)));
35973598

3598-
if (read(fd, ControlFile, sizeof(ControlFileData)) != sizeof(ControlFileData))
3599-
ereport(PANIC,
3600-
(errcode_for_file_access(),
3601-
errmsg("could not read from control file: %m")));
3599+
r = read(fd, ControlFile, sizeof(ControlFileData));
3600+
if (r != sizeof(ControlFileData))
3601+
{
3602+
if (r < 0)
3603+
ereport(PANIC,
3604+
(errcode_for_file_access(),
3605+
errmsg("could not read from control file: %m")));
3606+
else
3607+
ereport(PANIC,
3608+
(errmsg("could not read from control file: read %d bytes, expected %d", r, (int) sizeof(ControlFileData))));
3609+
}
36023610

36033611
close(fd);
36043612

0 commit comments

Comments
 (0)