mirror of
https://github.com/postgres/postgres.git
synced 2025-04-25 21:42:33 +03:00
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:
parent
a194106c1b
commit
cfb758b6d9
@ -4486,6 +4486,7 @@ ReadControlFile(void)
|
|||||||
pg_crc32c crc;
|
pg_crc32c crc;
|
||||||
int fd;
|
int fd;
|
||||||
static char wal_segsz_str[20];
|
static char wal_segsz_str[20];
|
||||||
|
int r;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read data...
|
* Read data...
|
||||||
@ -4499,10 +4500,17 @@ ReadControlFile(void)
|
|||||||
XLOG_CONTROL_FILE)));
|
XLOG_CONTROL_FILE)));
|
||||||
|
|
||||||
pgstat_report_wait_start(WAIT_EVENT_CONTROL_FILE_READ);
|
pgstat_report_wait_start(WAIT_EVENT_CONTROL_FILE_READ);
|
||||||
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))));
|
||||||
|
}
|
||||||
pgstat_report_wait_end();
|
pgstat_report_wait_end();
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -44,6 +44,7 @@ get_controlfile(const char *DataDir, const char *progname, bool *crc_ok_p)
|
|||||||
int fd;
|
int fd;
|
||||||
char ControlFilePath[MAXPGPATH];
|
char ControlFilePath[MAXPGPATH];
|
||||||
pg_crc32c crc;
|
pg_crc32c crc;
|
||||||
|
int r;
|
||||||
|
|
||||||
AssertArg(crc_ok_p);
|
AssertArg(crc_ok_p);
|
||||||
|
|
||||||
@ -64,18 +65,34 @@ get_controlfile(const char *DataDir, const char *progname, bool *crc_ok_p)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (read(fd, ControlFile, sizeof(ControlFileData)) != sizeof(ControlFileData))
|
r = read(fd, ControlFile, sizeof(ControlFileData));
|
||||||
#ifndef FRONTEND
|
if (r != sizeof(ControlFileData))
|
||||||
ereport(ERROR,
|
|
||||||
(errcode_for_file_access(),
|
|
||||||
errmsg("could not read file \"%s\": %m", ControlFilePath)));
|
|
||||||
#else
|
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("%s: could not read file \"%s\": %s\n"),
|
if (r < 0)
|
||||||
progname, ControlFilePath, strerror(errno));
|
#ifndef FRONTEND
|
||||||
exit(EXIT_FAILURE);
|
ereport(ERROR,
|
||||||
}
|
(errcode_for_file_access(),
|
||||||
|
errmsg("could not read file \"%s\": %m", ControlFilePath)));
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
fprintf(stderr, _("%s: could not read file \"%s\": %s\n"),
|
||||||
|
progname, ControlFilePath, strerror(errno));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
else
|
||||||
|
#ifndef FRONTEND
|
||||||
|
ereport(ERROR,
|
||||||
|
(errmsg("could not read file \"%s\": read %d bytes, expected %d",
|
||||||
|
ControlFilePath, r, (int) sizeof(ControlFileData))));
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
fprintf(stderr, _("%s: could not read file \"%s\": read %d bytes, expected %d\n"),
|
||||||
|
progname, ControlFilePath, r, (int) sizeof(ControlFileData));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user