aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2019-09-03 08:26:55 +0200
committerPeter Eisentraut <peter@eisentraut.org>2019-09-03 08:30:21 +0200
commit1d7a6e3eb45946db86d6d1776c55323740d955b0 (patch)
treea848299837c78551942a0052d0285d7e9897a0b6
parent396e4afdbcbfd3398415f1a0a29668d6a24a2ddd (diff)
downloadpostgresql-1d7a6e3eb45946db86d6d1776c55323740d955b0.tar.gz
postgresql-1d7a6e3eb45946db86d6d1776c55323740d955b0.zip
pg_checksums: Handle read and write returns correctly
The read() return was not checking for errors, the write() return was not checking for short writes. Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://www.postgresql.org/message-id/flat/5de61b6b-8be9-7771-0048-860328efe027%402ndquadrant.com
-rw-r--r--src/bin/pg_checksums/pg_checksums.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/bin/pg_checksums/pg_checksums.c b/src/bin/pg_checksums/pg_checksums.c
index 8c00ec9a3b1..971ae73f544 100644
--- a/src/bin/pg_checksums/pg_checksums.c
+++ b/src/bin/pg_checksums/pg_checksums.c
@@ -198,8 +198,12 @@ scan_file(const char *fn, BlockNumber segmentno)
break;
if (r != BLCKSZ)
{
- pg_log_error("could not read block %u in file \"%s\": read %d of %d",
- blockno, fn, r, BLCKSZ);
+ if (r < 0)
+ pg_log_error("could not read block %u in file \"%s\": %m",
+ blockno, fn);
+ else
+ pg_log_error("could not read block %u in file \"%s\": read %d of %d",
+ blockno, fn, r, BLCKSZ);
exit(1);
}
blocks++;
@@ -222,6 +226,8 @@ scan_file(const char *fn, BlockNumber segmentno)
}
else if (mode == PG_MODE_ENABLE)
{
+ int w;
+
/* Set checksum in page header */
header->pd_checksum = csum;
@@ -233,10 +239,15 @@ scan_file(const char *fn, BlockNumber segmentno)
}
/* Write block with checksum */
- if (write(f, buf.data, BLCKSZ) != BLCKSZ)
+ w = write(f, buf.data, BLCKSZ);
+ if (w != BLCKSZ)
{
- pg_log_error("could not write block %u in file \"%s\": %m",
- blockno, fn);
+ if (w < 0)
+ pg_log_error("could not write block %u in file \"%s\": %m",
+ blockno, fn);
+ else
+ pg_log_error("could not write block %u in file \"%s\": wrote %d of %d",
+ blockno, fn, w, BLCKSZ);
exit(1);
}
}