pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Postgres hackers <pgsql-hackers@postgresql.org>
Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Subject: Re: pgsql: Fix failure to check for open() or fsync() failures.
Date: Thu, 27 Dec 2018 07:43:51 +0900
Message-ID: <20181226224351.GA2106@paquier.xyz> (raw)
In-Reply-To: <E1gcGPf-0000Ih-1f@gemulon.postgresql.org>
References: <E1gcGPf-0000Ih-1f@gemulon.postgresql.org>

On Wed, Dec 26, 2018 at 09:08:23PM +0000, Tom Lane wrote:
> Fix failure to check for open() or fsync() failures.
> 
> While it seems OK to not be concerned about fsync() failure for a
> pre-existing signal file, it's not OK to not even check for open()
> failure.  This at least causes complaints from static analyzers,
> and I think on some platforms passing -1 to fsync() or close() might
> trigger assertion-type failures.  Also add (void) casts to make clear
> that we're ignoring fsync's result intentionally.
> 
> Oversights in commit 2dedf4d9a, noted by Coverity.

 fd = BasicOpenFilePerm(STANDBY_SIGNAL_FILE, O_RDWR | PG_BINARY | get_sync_bit(sync_method),
                        S_IRUSR | S_IWUSR);
-   pg_fsync(fd);
-   close(fd);
+   if (fd >= 0)
+   {
+       (void) pg_fsync(fd);
+       close(fd);
+   }

Wouldn't it be more simple to remove stat() and just call
BasicOpenFilePerm, complaining with FATAL about any failures,
including EACCES, on the way?  The code is racy as designed, even if
that's not a big deal for recovery purposes.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

view thread (7+ messages)  latest in thread

Message-ID: <20181226224351.GA2106@paquier.xyz>
Permalink:  ../20181226224351.GA2106@paquier.xyz/
Also on:    postgresql.org/message-id/20181226224351.GA2106@paquier.xyz

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz, tgl@sss.pgh.pa.us, pgsql-hackers@postgresql.org, peter.eisentraut@2ndquadrant.com
  Subject: Re: pgsql: Fix failure to check for open() or fsync() failures.
  In-Reply-To: <20181226224351.GA2106@paquier.xyz>
  References: <E1gcGPf-0000Ih-1f@gemulon.postgresql.org> <20181226224351.GA2106@paquier.xyz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox