Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1flgJa-0006EN-Pj for pgsql-committers@arkaria.postgresql.org; Fri, 03 Aug 2018 20:04:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1flgJX-0000zT-4k for pgsql-committers@arkaria.postgresql.org; Fri, 03 Aug 2018 20:04:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1flgJX-0000zM-05 for pgsql-committers@lists.postgresql.org; Fri, 03 Aug 2018 20:04:43 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1flgJT-0005n2-U9 for pgsql-committers@lists.postgresql.org; Fri, 03 Aug 2018 20:04:42 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w73K4atb031798; Fri, 3 Aug 2018 16:04:36 -0400 From: Tom Lane To: Michael Paquier cc: pgsql-committers@lists.postgresql.org Subject: Re: pgsql: Address set of issues with errno handling In-reply-to: References: Comments: In-reply-to Michael Paquier message dated "Mon, 25 Jun 2018 02:23:59 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <31796.1533326676.1@sss.pgh.pa.us> Date: Fri, 03 Aug 2018 16:04:36 -0400 Message-ID: <31797.1533326676@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Michael Paquier writes: > Address set of issues with errno handling I happened to look at this patch while working up the release notes, and I don't think it's right at all for this aspect: > 1) For write() calls, sometimes the system may return less bytes than > what has been written without errno being set. Some paths were careful > enough to consider that case, and assumed that errno should be set to > ENOSPC, other calls missed that. AFAICS, what you did about that was like this: @@ -816,7 +828,12 @@ tar_close(Walfile f, WalCloseMethod method) if (!tar_data->compression) { if (write(tar_data->fd, tf->header, 512) != 512) + { + /* if write didn't set errno, assume problem is no disk space */ + if (errno == 0) + errno = ENOSPC; return -1; + } } #ifdef HAVE_LIBZ else That's not good enough, because there is no reason to suppose that errno is initially zero; in reality it'll be whatever was left over from the last failed syscall, perhaps far distant from here. The places that do this correctly do it like so: errno = 0; if (write(...) != expected-length) { /* if write didn't set errno, assume problem is no disk space */ if (errno == 0) errno = ENOSPC; ... } You need to go back and add the pre-clearing of errno in each of these places, otherwise the added code is basically useless. regards, tom lane