Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gcL8T-00039J-LT for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Dec 2018 02:10:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gcL8Q-0007DN-6Q for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Dec 2018 02:10:54 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1gcL8O-0007DG-A7 for pgsql-hackers@lists.postgresql.org; Thu, 27 Dec 2018 02:10:54 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gcL8I-0004im-Eq for pgsql-hackers@postgresql.org; Thu, 27 Dec 2018 02:10:51 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id E7E0E21D72; Wed, 26 Dec 2018 21:10:44 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 26 Dec 2018 21:10:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=1phdhmdwbHwQHCbLtHZrh8Qd+au YiUt1B6gUiAqURzk=; b=L8gNC61awlw9IocuRsMrYm9Y/h4vY36UD5qZO2DHc90 7Zx+a218v4SXUGDms52NeuZAJtI2Aeogrl8L+mauVa7Kzz8H/PU7LhBwMIUkDiqn JsTfqTYBZsuOINrJgoqZGGoyfl2i+3kDPl6xqJCfEqU0z7ovyvKm4whjIeHM8VSW /unqicrIkJJaEQKOEl0azNggtOGHQvTSIambYanPOAcc9hnoEuYNlcY6Dx4CsIQE KVnd5ej6RGC9CPAhB3ALbxOoTdi2FOYjf+fZKzyih3EISa5IdBSr32536EJM8jAj Iq2v/gk5eVlUmoARm8cr5gVQV4HejH1BcNyhttlMg6A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=1phdhm dwbHwQHCbLtHZrh8Qd+auYiUt1B6gUiAqURzk=; b=LMGTxgr6+eiy8OlYN2Q+Os oAwUe+k+UXUP0DYsq9C7kzLZSrJwcsF9EhZJVH+NDEkQ6R+DlYvhPCpOJxBFoC2g j4j3Bo71yigkM9SwlQBiLxGJOeMEejL3ju9a63rgGL19TQeH4X6g4G1KG91nJIM0 pLviw4/QHvXRuE0g76n34uziS0KuxPgoubQd/mUtXT/yHLdij/dqsMSVCeBuyPLQ 61ntTku+rpCmqtRaW3JmP0A5WP8Non97kxd5SeMa1CxmMsuE7+K+ta0K4pAJ/QrO MZUdTqA6RFLS95O4aG/RDIhwujW2TN0J6SX6s00lvjctSABWmHZM9aFDNdbhzrdA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrtddugdeggeculddtuddrgedtkedrtddtmd cutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucfkphepiedurddvudehrddufeejrdduiedvnecurfgrrhgr mhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiiinecuvehluh hsthgvrhfuihiivgeptd X-ME-Proxy: Received: from paquier.xyz (c137162.net61215.cablenet.ne.jp [61.215.137.162]) by mail.messagingengine.com (Postfix) with ESMTPA id 7451210085; Wed, 26 Dec 2018 21:10:42 -0500 (EST) Date: Thu, 27 Dec 2018 11:10:39 +0900 From: Michael Paquier To: Tom Lane Cc: Postgres hackers , Peter Eisentraut Subject: Re: pgsql: Fix failure to check for open() or fsync() failures. Message-ID: <20181227021039.GI2106@paquier.xyz> References: <20181226224351.GA2106@paquier.xyz> <26009.1545864936@sss.pgh.pa.us> <20181227010918.GC2106@paquier.xyz> <32282.1545874522@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="yr/DzoowOgTDcSCF" Content-Disposition: inline In-Reply-To: <32282.1545874522@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --yr/DzoowOgTDcSCF Content-Type: multipart/mixed; boundary="3U8TY7m7wOx7RL1F" Content-Disposition: inline --3U8TY7m7wOx7RL1F Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Dec 26, 2018 at 08:35:22PM -0500, Tom Lane wrote: > Oh, I see. Yeah, if we're ignoring errors anyway, the stat calls > seem redundant. For this one, I think that we could simplify as attached (this causes open() to fail additionally because of the sync flags, but that's not really worth worrying). Thoughts? -- Michael --3U8TY7m7wOx7RL1F Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="recovery-signal-simplify.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam= /xlog.c index 5729867879..34ebf6716e 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -5307,6 +5307,7 @@ static void readRecoverySignalFile(void) { struct stat stat_buf; + int fd; =20 if (IsBootstrapProcessingMode()) return; @@ -5333,30 +5334,20 @@ readRecoverySignalFile(void) * If present, standby signal file takes precedence. If neither is present * then we won't enter archive recovery. */ - if (stat(STANDBY_SIGNAL_FILE, &stat_buf) =3D=3D 0) + if ((fd =3D BasicOpenFilePerm(STANDBY_SIGNAL_FILE, + O_RDWR | PG_BINARY | get_sync_bit(sync_method), + S_IRUSR | S_IWUSR)) >=3D 0) { - int fd; - - fd =3D BasicOpenFilePerm(STANDBY_SIGNAL_FILE, O_RDWR | PG_BINARY | get_s= ync_bit(sync_method), - S_IRUSR | S_IWUSR); - if (fd >=3D 0) - { - (void) pg_fsync(fd); - close(fd); - } + (void) pg_fsync(fd); + close(fd); standby_signal_file_found =3D true; } - else if (stat(RECOVERY_SIGNAL_FILE, &stat_buf) =3D=3D 0) + else if ((fd =3D BasicOpenFilePerm(RECOVERY_SIGNAL_FILE, + O_RDWR | PG_BINARY | get_sync_bit(sync_method), + S_IRUSR | S_IWUSR)) >=3D 0) { - int fd; - - fd =3D BasicOpenFilePerm(RECOVERY_SIGNAL_FILE, O_RDWR | PG_BINARY | get_= sync_bit(sync_method), - S_IRUSR | S_IWUSR); - if (fd >=3D 0) - { - (void) pg_fsync(fd); - close(fd); - } + (void) pg_fsync(fd); + close(fd); recovery_signal_file_found =3D true; } =20 --3U8TY7m7wOx7RL1F-- --yr/DzoowOgTDcSCF Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlwkNJ8ACgkQnvQgOdby QH1PAQ//XGI64g0vr9xXni2qCUlkj8fkw7JvWKsutQLzrYCvDyQTm8iXCP+uOjxz 6DV2ZpbpRuEp18sHRj55x+/1+DiErp9Z2fREj/dmEPU7/howBSsXRieol07j8ZTZ Ay+GhiuQ9claO7ZG7s+THOJbEMLWctUwAftUtkhaPhfCDejRGTYgbDKzzsXBCE1A RxvbdjXYNDnOaAd6Zx2rXuvveYfAexpHwDxVUnfzf02T86sy2z6CgDJIFN2KOBD7 f71y37LnTIXBi4RAQ4fUzv7AqfTxKnsFfwqZX1NJkHbzF9m7EXV8Plq3/788K/2f jqB9MfSPgjqJ06tfp+QxvwOUXX6q9gh9So1a5I6Nj4vQRg/b8gjrXfhWgYnYt0Mx MzCmCVFe19PyqlrrU2yMfBXIzIlrwUMJ1aJOFS5xVNcW+uIiEsY3/2w8uuQXjeZL +wcRQZNG4xqNtP9ioThTJxuBhmd9NP5/R4UyCM5WGjHe7pM2/jFZOVFadA5m5o6F x8NIN067oy0SbIBJ8kS7FyW+tp+BaxqIq2ndQOZAq9hHpPvVltBCFA1+ykPIiGf7 wZFGu/eBAi1yzFBO876x7iZGtGtcUtqF8W4RHqp1/x8B2c2tOtqN5GNI1V3iPZI3 Q298yCGR75FCe9D19cNAZOhfXXgjC52TvgZyvmqXiOiKj+24wtQ= =A0zJ -----END PGP SIGNATURE----- --yr/DzoowOgTDcSCF--