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
This commit is contained in:
parent
396e4afdbc
commit
1d7a6e3eb4
|
@ -198,6 +198,10 @@ scan_file(const char *fn, BlockNumber segmentno)
|
||||||
break;
|
break;
|
||||||
if (r != BLCKSZ)
|
if (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",
|
pg_log_error("could not read block %u in file \"%s\": read %d of %d",
|
||||||
blockno, fn, r, BLCKSZ);
|
blockno, fn, r, BLCKSZ);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -222,6 +226,8 @@ scan_file(const char *fn, BlockNumber segmentno)
|
||||||
}
|
}
|
||||||
else if (mode == PG_MODE_ENABLE)
|
else if (mode == PG_MODE_ENABLE)
|
||||||
{
|
{
|
||||||
|
int w;
|
||||||
|
|
||||||
/* Set checksum in page header */
|
/* Set checksum in page header */
|
||||||
header->pd_checksum = csum;
|
header->pd_checksum = csum;
|
||||||
|
|
||||||
|
@ -233,10 +239,15 @@ scan_file(const char *fn, BlockNumber segmentno)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write block with checksum */
|
/* Write block with checksum */
|
||||||
if (write(f, buf.data, BLCKSZ) != BLCKSZ)
|
w = write(f, buf.data, BLCKSZ);
|
||||||
|
if (w != BLCKSZ)
|
||||||
{
|
{
|
||||||
|
if (w < 0)
|
||||||
pg_log_error("could not write block %u in file \"%s\": %m",
|
pg_log_error("could not write block %u in file \"%s\": %m",
|
||||||
blockno, fn);
|
blockno, fn);
|
||||||
|
else
|
||||||
|
pg_log_error("could not write block %u in file \"%s\": wrote %d of %d",
|
||||||
|
blockno, fn, w, BLCKSZ);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue