Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1d7a6e3

Browse files
committed
pg_checksums: Handle read and write returns correctly
The read() return was not checking for errors, the write() return wasnot 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
1 parent396e4af commit1d7a6e3

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

‎src/bin/pg_checksums/pg_checksums.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,12 @@ scan_file(const char *fn, BlockNumber segmentno)
198198
break;
199199
if (r!=BLCKSZ)
200200
{
201-
pg_log_error("could not read block %u in file \"%s\": read %d of %d",
202-
blockno,fn,r,BLCKSZ);
201+
if (r<0)
202+
pg_log_error("could not read block %u in file \"%s\": %m",
203+
blockno,fn);
204+
else
205+
pg_log_error("could not read block %u in file \"%s\": read %d of %d",
206+
blockno,fn,r,BLCKSZ);
203207
exit(1);
204208
}
205209
blocks++;
@@ -222,6 +226,8 @@ scan_file(const char *fn, BlockNumber segmentno)
222226
}
223227
elseif (mode==PG_MODE_ENABLE)
224228
{
229+
intw;
230+
225231
/* Set checksum in page header */
226232
header->pd_checksum=csum;
227233

@@ -233,10 +239,15 @@ scan_file(const char *fn, BlockNumber segmentno)
233239
}
234240

235241
/* Write block with checksum */
236-
if (write(f,buf.data,BLCKSZ)!=BLCKSZ)
242+
w=write(f,buf.data,BLCKSZ);
243+
if (w!=BLCKSZ)
237244
{
238-
pg_log_error("could not write block %u in file \"%s\": %m",
239-
blockno,fn);
245+
if (w<0)
246+
pg_log_error("could not write block %u in file \"%s\": %m",
247+
blockno,fn);
248+
else
249+
pg_log_error("could not write block %u in file \"%s\": wrote %d of %d",
250+
blockno,fn,w,BLCKSZ);
240251
exit(1);
241252
}
242253
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp