mirror of
https://github.com/postgres/postgres.git
synced 2025-05-09 18:21:05 +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
4a9b44d3c0
commit
830e8e3609
@ -4311,6 +4311,7 @@ ReadControlFile(void)
|
|||||||
{
|
{
|
||||||
pg_crc32c crc;
|
pg_crc32c crc;
|
||||||
int fd;
|
int fd;
|
||||||
|
int r;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read data...
|
* Read data...
|
||||||
@ -4324,10 +4325,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));
|
||||||
|
if (r != sizeof(ControlFileData))
|
||||||
|
{
|
||||||
|
if (r < 0)
|
||||||
ereport(PANIC,
|
ereport(PANIC,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not read from control file: %m")));
|
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);
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ get_controlfile(char *DataDir, const char *progname)
|
|||||||
int fd;
|
int fd;
|
||||||
char ControlFilePath[MAXPGPATH];
|
char ControlFilePath[MAXPGPATH];
|
||||||
pg_crc32c crc;
|
pg_crc32c crc;
|
||||||
|
int r;
|
||||||
|
|
||||||
ControlFile = palloc(sizeof(ControlFileData));
|
ControlFile = palloc(sizeof(ControlFileData));
|
||||||
snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir);
|
snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir);
|
||||||
@ -59,7 +60,10 @@ get_controlfile(char *DataDir, const char *progname)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (read(fd, ControlFile, sizeof(ControlFileData)) != sizeof(ControlFileData))
|
r = read(fd, ControlFile, sizeof(ControlFileData));
|
||||||
|
if (r != sizeof(ControlFileData))
|
||||||
|
{
|
||||||
|
if (r < 0)
|
||||||
#ifndef FRONTEND
|
#ifndef FRONTEND
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
@ -71,6 +75,19 @@ get_controlfile(char *DataDir, const char *progname)
|
|||||||
exit(EXIT_FAILURE);
|
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