Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jm27A-0006xJ-BE for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jun 2020 21:30:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jm279-0006cE-9M for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jun 2020 21:30:27 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jm279-0006c7-2G for pgsql-hackers@lists.postgresql.org; Thu, 18 Jun 2020 21:30:27 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jm275-0003XC-R8 for pgsql-hackers@postgresql.org; Thu, 18 Jun 2020 21:30:25 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 05ILUIw11597086; Thu, 18 Jun 2020 17:30:18 -0400 From: Tom Lane To: Alvaro Herrera cc: Justin Pryzby , pgsql-hackers@postgresql.org, Kunshchikov Vladimir Subject: Re: pg_dump, gzwrite, and errno In-reply-to: <20200618212027.GA17103@alvherre.pgsql> References: <20200618212027.GA17103@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Thu, 18 Jun 2020 17:20:27 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1597084.1592515818.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 18 Jun 2020 17:30:18 -0400 Message-ID: <1597085.1592515818@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alvaro Herrera writes: > On 2020-Jun-11, Justin Pryzby wrote: >> --- a/src/bin/pg_dump/pg_backup_directory.c >> +++ b/src/bin/pg_dump/pg_backup_directory.c >> @@ -347,8 +347,12 @@ _WriteData(ArchiveHandle *AH, const void *data, si= ze_t dLen) >> lclContext *ctx =3D (lclContext *) AH->formatData; >> = >> if (dLen > 0 && cfwrite(data, dLen, ctx->dataFH) !=3D dLen) >> + { >> + if (errno =3D=3D 0) >> + errno =3D ENOSPC; >> fatal("could not write to output file: %s", >> get_cfp_error(ctx->dataFH)); >> + } >> } > This seems correct to me. Surely it's insufficient as-is, because there is no reason to suppose that errno is zero at entry. You'd need to set errno =3D 0 first. Also it's fairly customary in our sources to include a comment about this machination; so the full ritual is usually more like errno =3D 0; if (pg_pwrite(fd, data, len, xlrec->offset) !=3D len) { /* if write didn't set errno, assume problem is no disk space */ if (errno =3D=3D 0) errno =3D ENOSPC; ereport ... > (I spent a long time looking at zlib sources > to convince myself that it does work with compressed files too) Yeah, it's not obvious that gzwrite has the same behavior w.r.t. errno as a plain write. But there's not much we can do to improve matters if it does not, so we might as well assume it does. regards, tom lane