mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-13 17:08:09 +02: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:
parent
0a60a291c9
commit
f5b4bb8812
@ -1162,6 +1162,7 @@ heap_xlog_logical_rewrite(XLogReaderState *r)
|
||||
len = xlrec->num_mappings * sizeof(LogicalRewriteMappingData);
|
||||
|
||||
/* write out tail end of mapping file (again) */
|
||||
errno = 0;
|
||||
if (write(fd, data, len) != len)
|
||||
{
|
||||
/* if write didn't set errno, assume problem is no disk space */
|
||||
|
@ -1553,6 +1553,7 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len)
|
||||
path)));
|
||||
|
||||
/* Write content and CRC */
|
||||
errno = 0;
|
||||
if (write(fd, content, len) != len)
|
||||
{
|
||||
int save_errno = errno;
|
||||
|
@ -547,6 +547,7 @@ CheckPointReplicationOrigin(void)
|
||||
tmppath)));
|
||||
|
||||
/* write magic */
|
||||
errno = 0;
|
||||
if ((write(tmpfd, &magic, sizeof(magic))) != sizeof(magic))
|
||||
{
|
||||
int save_errno = errno;
|
||||
@ -590,6 +591,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))
|
||||
{
|
||||
@ -612,6 +614,7 @@ CheckPointReplicationOrigin(void)
|
||||
|
||||
/* write out the CRC */
|
||||
FIN_CRC32C(crc);
|
||||
errno = 0;
|
||||
if ((write(tmpfd, &crc, sizeof(crc))) != sizeof(crc))
|
||||
{
|
||||
int save_errno = errno;
|
||||
|
@ -2479,6 +2479,7 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
|
||||
|
||||
ondisk->size = sz;
|
||||
|
||||
errno = 0;
|
||||
if (write(fd, rb->outbuf, ondisk->size) != ondisk->size)
|
||||
{
|
||||
int save_errno = errno;
|
||||
|
@ -1588,6 +1588,7 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
|
||||
ereport(ERROR,
|
||||
(errmsg("could not open file \"%s\": %m", path)));
|
||||
|
||||
errno = 0;
|
||||
if ((write(fd, ondisk, needed_length)) != needed_length)
|
||||
{
|
||||
int save_errno = errno;
|
||||
|
@ -1080,6 +1080,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
|
||||
SnapBuildOnDiskChecksummedSize);
|
||||
FIN_CRC32C(cp.checksum);
|
||||
|
||||
errno = 0;
|
||||
if ((write(fd, &cp, sizeof(cp))) != sizeof(cp))
|
||||
{
|
||||
int save_errno = errno;
|
||||
|
@ -147,6 +147,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
|
||||
zerobuf = pg_malloc0(XLOG_BLCKSZ);
|
||||
for (bytes = 0; bytes < XLogSegSize; bytes += XLOG_BLCKSZ)
|
||||
{
|
||||
errno = 0;
|
||||
if (write(f, zerobuf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
|
||||
{
|
||||
/* if write didn't set errno, assume problem is no disk space */
|
||||
@ -1189,6 +1190,7 @@ ProcessXLogDataMsg(PGconn *conn, StreamCtl *stream, char *copybuf, int len,
|
||||
}
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
if (write(walfile,
|
||||
copybuf + hdr_len + bytes_written,
|
||||
bytes_to_write) != bytes_to_write)
|
||||
|
Loading…
Reference in New Issue
Block a user