git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 396e4af)
pg_checksums: Handle read and write returns correctly
Tue, 3 Sep 2019 06:26:55 +0000 (08:26 +0200)
Tue, 3 Sep 2019 06:30:21 +0000 (08:30 +0200)
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


diff --git a/src/bin/pg_checksums/pg_checksums.c b/src/bin/pg_checksums/pg_checksums.c
index 8c00ec9a3b1a27177cf1db8de96e4354d0452585..971ae73f5444ac07372c6f6ef604edd345651a2d 100644 (file)
--- 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);
}
}
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /