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

Commit5a23c74

Browse files
committed
Reset properly errno before calling write()
6cb3372 enforces errno to ENOSPC when less bytes than what is expectedhave been written when it is unset, though it forgot to properly reseterrno before doing a system call to write(), causing errno topotentially come from a previous system call.Reported-by: Tom LaneAuthor: Michael PaquierReviewed-by: Tom LaneDiscussion:https://postgr.es/m/31797.1533326676@sss.pgh.pa.us
1 parente61f21b commit5a23c74

File tree

7 files changed

+14
-0
lines changed

7 files changed

+14
-0
lines changed

‎src/backend/access/heap/rewriteheap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,7 @@ heap_xlog_logical_rewrite(XLogReaderState *r)
11661166
len=xlrec->num_mappings*sizeof(LogicalRewriteMappingData);
11671167

11681168
/* write out tail end of mapping file (again) */
1169+
errno=0;
11691170
pgstat_report_wait_start(WAIT_EVENT_LOGICAL_REWRITE_MAPPING_WRITE);
11701171
if (write(fd,data,len)!=len)
11711172
{

‎src/backend/access/transam/twophase.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,7 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len)
16691669
errmsg("could not recreate file \"%s\": %m",path)));
16701670

16711671
/* Write content and CRC */
1672+
errno=0;
16721673
pgstat_report_wait_start(WAIT_EVENT_TWOPHASE_FILE_WRITE);
16731674
if (write(fd,content,len)!=len)
16741675
{

‎src/backend/replication/logical/origin.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ CheckPointReplicationOrigin(void)
576576
tmppath)));
577577

578578
/* write magic */
579+
errno=0;
579580
if ((write(tmpfd,&magic,sizeof(magic)))!=sizeof(magic))
580581
{
581582
intsave_errno=errno;
@@ -619,6 +620,7 @@ CheckPointReplicationOrigin(void)
619620
/* make sure we only write out a commit that's persistent */
620621
XLogFlush(local_lsn);
621622

623+
errno=0;
622624
if ((write(tmpfd,&disk_state,sizeof(disk_state)))!=
623625
sizeof(disk_state))
624626
{
@@ -641,6 +643,7 @@ CheckPointReplicationOrigin(void)
641643

642644
/* write out the CRC */
643645
FIN_CRC32C(crc);
646+
errno=0;
644647
if ((write(tmpfd,&crc,sizeof(crc)))!=sizeof(crc))
645648
{
646649
intsave_errno=errno;

‎src/backend/replication/logical/reorderbuffer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,6 +2421,7 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
24212421

24222422
ondisk->size=sz;
24232423

2424+
errno=0;
24242425
pgstat_report_wait_start(WAIT_EVENT_REORDER_BUFFER_WRITE);
24252426
if (write(fd,rb->outbuf,ondisk->size)!=ondisk->size)
24262427
{

‎src/backend/replication/logical/snapbuild.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,7 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
16091609
ereport(ERROR,
16101610
(errmsg("could not open file \"%s\": %m",path)));
16111611

1612+
errno=0;
16121613
pgstat_report_wait_start(WAIT_EVENT_SNAPBUILD_WRITE);
16131614
if ((write(fd,ondisk,needed_length))!=needed_length)
16141615
{

‎src/backend/replication/slot.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
12751275
SnapBuildOnDiskChecksummedSize);
12761276
FIN_CRC32C(cp.checksum);
12771277

1278+
errno=0;
12781279
pgstat_report_wait_start(WAIT_EVENT_REPLICATION_SLOT_WRITE);
12791280
if ((write(fd,&cp,sizeof(cp)))!=sizeof(cp))
12801281
{

‎src/bin/pg_basebackup/walmethods.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
122122
zerobuf=pg_malloc0(XLOG_BLCKSZ);
123123
for (bytes=0;bytes<pad_to_size;bytes+=XLOG_BLCKSZ)
124124
{
125+
errno=0;
125126
if (write(fd,zerobuf,XLOG_BLCKSZ)!=XLOG_BLCKSZ)
126127
{
127128
intsave_errno=errno;
@@ -445,6 +446,7 @@ tar_write_compressed_data(void *buf, size_t count, bool flush)
445446
{
446447
size_tlen=ZLIB_OUT_SIZE-tar_data->zp->avail_out;
447448

449+
errno=0;
448450
if (write(tar_data->fd,tar_data->zlibOut,len)!=len)
449451
{
450452
/*
@@ -629,6 +631,7 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
629631

630632
if (!tar_data->compression)
631633
{
634+
errno=0;
632635
if (write(tar_data->fd,tar_data->currentfile->header,512)!=512)
633636
{
634637
save_errno=errno;
@@ -829,6 +832,7 @@ tar_close(Walfile f, WalCloseMethod method)
829832
return-1;
830833
if (!tar_data->compression)
831834
{
835+
errno=0;
832836
if (write(tar_data->fd,tf->header,512)!=512)
833837
{
834838
/* if write didn't set errno, assume problem is no disk space */
@@ -901,6 +905,7 @@ tar_finish(void)
901905
MemSet(zerobuf,0,sizeof(zerobuf));
902906
if (!tar_data->compression)
903907
{
908+
errno=0;
904909
if (write(tar_data->fd,zerobuf,sizeof(zerobuf))!=sizeof(zerobuf))
905910
{
906911
/* if write didn't set errno, assume problem is no disk space */
@@ -933,6 +938,7 @@ tar_finish(void)
933938
{
934939
size_tlen=ZLIB_OUT_SIZE-tar_data->zp->avail_out;
935940

941+
errno=0;
936942
if (write(tar_data->fd,tar_data->zlibOut,len)!=len)
937943
{
938944
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp