mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Reset properly errno before calling write()
6cb3372 enforces errno to ENOSPC when less bytes than what is expected
have been written when it is unset, though it forgot to properly reset
errno before doing a system call to write(), causing errno to
potentially come from a previous system call.
Reported-by: Tom Lane
Author: Michael Paquier
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/31797.1533326676@sss.pgh.pa.us
			
			
This commit is contained in:
		@@ -1166,6 +1166,7 @@ heap_xlog_logical_rewrite(XLogReaderState *r)
 | 
			
		||||
	len = xlrec->num_mappings * sizeof(LogicalRewriteMappingData);
 | 
			
		||||
 | 
			
		||||
	/* write out tail end of mapping file (again) */
 | 
			
		||||
	errno = 0;
 | 
			
		||||
	pgstat_report_wait_start(WAIT_EVENT_LOGICAL_REWRITE_MAPPING_WRITE);
 | 
			
		||||
	if (write(fd, data, len) != len)
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
@@ -1669,6 +1669,7 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len)
 | 
			
		||||
				 errmsg("could not recreate file \"%s\": %m", path)));
 | 
			
		||||
 | 
			
		||||
	/* Write content and CRC */
 | 
			
		||||
	errno = 0;
 | 
			
		||||
	pgstat_report_wait_start(WAIT_EVENT_TWOPHASE_FILE_WRITE);
 | 
			
		||||
	if (write(fd, content, len) != len)
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
@@ -576,6 +576,7 @@ CheckPointReplicationOrigin(void)
 | 
			
		||||
						tmppath)));
 | 
			
		||||
 | 
			
		||||
	/* write magic */
 | 
			
		||||
	errno = 0;
 | 
			
		||||
	if ((write(tmpfd, &magic, sizeof(magic))) != sizeof(magic))
 | 
			
		||||
	{
 | 
			
		||||
		int			save_errno = errno;
 | 
			
		||||
@@ -619,6 +620,7 @@ CheckPointReplicationOrigin(void)
 | 
			
		||||
		/* make sure we only write out a commit that's persistent */
 | 
			
		||||
		XLogFlush(local_lsn);
 | 
			
		||||
 | 
			
		||||
		errno = 0;
 | 
			
		||||
		if ((write(tmpfd, &disk_state, sizeof(disk_state))) !=
 | 
			
		||||
			sizeof(disk_state))
 | 
			
		||||
		{
 | 
			
		||||
@@ -641,6 +643,7 @@ CheckPointReplicationOrigin(void)
 | 
			
		||||
 | 
			
		||||
	/* write out the CRC */
 | 
			
		||||
	FIN_CRC32C(crc);
 | 
			
		||||
	errno = 0;
 | 
			
		||||
	if ((write(tmpfd, &crc, sizeof(crc))) != sizeof(crc))
 | 
			
		||||
	{
 | 
			
		||||
		int			save_errno = errno;
 | 
			
		||||
 
 | 
			
		||||
@@ -2421,6 +2421,7 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
 | 
			
		||||
 | 
			
		||||
	ondisk->size = sz;
 | 
			
		||||
 | 
			
		||||
	errno = 0;
 | 
			
		||||
	pgstat_report_wait_start(WAIT_EVENT_REORDER_BUFFER_WRITE);
 | 
			
		||||
	if (write(fd, rb->outbuf, ondisk->size) != ondisk->size)
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
@@ -1609,6 +1609,7 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
 | 
			
		||||
		ereport(ERROR,
 | 
			
		||||
				(errmsg("could not open file \"%s\": %m", path)));
 | 
			
		||||
 | 
			
		||||
	errno = 0;
 | 
			
		||||
	pgstat_report_wait_start(WAIT_EVENT_SNAPBUILD_WRITE);
 | 
			
		||||
	if ((write(fd, ondisk, needed_length)) != needed_length)
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
@@ -1275,6 +1275,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
 | 
			
		||||
				SnapBuildOnDiskChecksummedSize);
 | 
			
		||||
	FIN_CRC32C(cp.checksum);
 | 
			
		||||
 | 
			
		||||
	errno = 0;
 | 
			
		||||
	pgstat_report_wait_start(WAIT_EVENT_REPLICATION_SLOT_WRITE);
 | 
			
		||||
	if ((write(fd, &cp, sizeof(cp))) != sizeof(cp))
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user