aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMagnus Hagander <magnus@hagander.net>2018-05-18 17:53:12 +0200
committerMagnus Hagander <magnus@hagander.net>2018-05-18 17:53:12 +0200
commit29ce50091d128faaabd0a4044e91a7d0da11bb8e (patch)
tree3f9063477a03fd26d523cf08d74ea331efd14f30 /src
parentee68541ce60dd585cbc53142ab9cd14bf10fdf8f (diff)
downloadpostgresql-29ce50091d128faaabd0a4044e91a7d0da11bb8e.tar.gz
postgresql-29ce50091d128faaabd0a4044e91a7d0da11bb8e.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/access/transam/xlog.c16
-rw-r--r--src/common/controldata_utils.c35
2 files changed, 38 insertions, 13 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 742e0e7115e..0cb1e9981a8 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -4475,6 +4475,7 @@ ReadControlFile(void)
{
pg_crc32c crc;
int fd;
+ int r;
/*
* Read data...
@@ -4489,10 +4490,17 @@ ReadControlFile(void)
XLOG_CONTROL_FILE)));
pgstat_report_wait_start(WAIT_EVENT_CONTROL_FILE_READ);
- 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))));
+ }
pgstat_report_wait_end();
close(fd);
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c
index f1a097a9746..0aabb0d8643 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -44,6 +44,7 @@ get_controlfile(const char *DataDir, const char *progname, bool *crc_ok_p)
int fd;
char ControlFilePath[MAXPGPATH];
pg_crc32c crc;
+ int r;
AssertArg(crc_ok_p);
@@ -64,18 +65,34 @@ get_controlfile(const char *DataDir, const char *progname, bool *crc_ok_p)
}
#endif
- if (read(fd, ControlFile, sizeof(ControlFileData)) != sizeof(ControlFileData))
+ r = read(fd, ControlFile, sizeof(ControlFileData));
+ if (r != sizeof(ControlFileData))
+ {
+ if (r < 0)
#ifndef FRONTEND
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not read file \"%s\": %m", ControlFilePath)));
+ 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);
- }
+ {
+ fprintf(stderr, _("%s: could not read file \"%s\": %s\n"),
+ progname, ControlFilePath, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
#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);