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
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 */
path)));
/* Write content and CRC */
+ errno = 0;
if (write(fd, content, len) != len)
{
int save_errno = errno;
ondisk->size = sz;
+ errno = 0;
if (write(fd, rb->outbuf, ondisk->size) != ondisk->size)
{
int save_errno = errno;
ereport(ERROR,
(errmsg("could not open file \"%s\": %m", path)));
+ errno = 0;
if ((write(fd, ondisk, needed_length)) != needed_length)
{
int save_errno = errno;
SnapBuildOnDiskChecksummedSize);
FIN_CRC32(cp.checksum);
+ errno = 0;
if ((write(fd, &cp, sizeof(cp))) != sizeof(cp))
{
int save_errno = errno;
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 */
}
}
+ errno = 0;
if (write(walfile,
copybuf + hdr_len + bytes_written,
bytes_to_write) != bytes_to_write)