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 1gcHuN-0008Oq-03 for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Dec 2018 22:44:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gcHuK-0001fI-3Y for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Dec 2018 22:44:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gcHuI-0001fB-7o for pgsql-hackers@lists.postgresql.org; Wed, 26 Dec 2018 22:44:07 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gcHuA-0000DS-6n for pgsql-hackers@postgresql.org; Wed, 26 Dec 2018 22:44:04 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 2B3E72210E; Wed, 26 Dec 2018 17:43:57 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 26 Dec 2018 17:43:57 -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=cwvISsMLfjLMcD932tNFHpGNd+r 2hB1QiY3UbOhUreg=; b=NMd36DXJSUUDsxX8KzrPlD01rE0Ee00rxORwEwQdZLK Zoq2r5pzLi+hA/LxUsWgLIrDkK05ZWqbeIgP6okUTiHuRx4SujHOuGMsJlFsZWDE gBU72iLJJkXhJk2ytzXv+uSRy/Q1Aonh/S69W/HwZhHFa2HZ8ANw2M8Vym6t81Kd gi45oW89DoVbOT/OoHEf/riXEIg6KveQcb6JTxq2cRvhXT3K9dGC2ZVNslprQDC2 TtXWqfyttHQJuPE9J3Z0Tdlk/X1JzFYKh5YM1fxlc/VRbeJCOkGK7Mc1C3He53G+ m86RQ53ngbnU14IEnkSbHEYvEEv9iO/35Jy7UHqLpLQ== 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=cwvISs MLfjLMcD932tNFHpGNd+r2hB1QiY3UbOhUreg=; b=A1GS180yU32XjgmX4e/5fZ k47/P6mWFmkWFlsOY0EaIUuMBUO1ImOn9/67kWJvHuS4EY203+CIbrdHXzPKEkoO SCSrfYjHTF8O+RFDv2wrQw4KkcPucBDIeflVREFzJhe8m4MwrzFQ1bA8NWRyqOkq UemwvMxgUSRDLnWOJvCq1F560GtomykxalT9g8ZWyePODQCxX7Z1IEJqS9mI7EJB y2KTMAKqiFzVqdbqCnTiEkDr08Y7VvUzD0N4pZ9Q9/J7TVAv6CCXH9xIzLsViRna AYTTP+5IoYOm4AmoqwgUXGo0o0ytPB8zkgUOhyY3JMg/ZgVl0zIa7GDrBb8VCTGg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrtdduucdltddurdegtdekrddttddmucetuf doteggodetrfdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfquhhtnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfghrlh cuvffnffculdejtddmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecu hfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqhhuih gvrhdrgiihiieqnecukfhppeeiuddrvdduhedrudefjedrudeivdenucfrrghrrghmpehm rghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiienucevlhhushhtvg hrufhiiigvpedt X-ME-Proxy: Received: from paquier.xyz (c137162.net61215.cablenet.ne.jp [61.215.137.162]) by mail.messagingengine.com (Postfix) with ESMTPA id 89FE7E453B; Wed, 26 Dec 2018 17:43:54 -0500 (EST) Date: Thu, 27 Dec 2018 07:43:51 +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: <20181226224351.GA2106@paquier.xyz> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="rwEMma7ioTxnRzrJ" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --rwEMma7ioTxnRzrJ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Dec 26, 2018 at 09:08:23PM +0000, Tom Lane wrote: > Fix failure to check for open() or fsync() failures. >=20 > 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. >=20 > Oversights in commit 2dedf4d9a, noted by Coverity. fd =3D BasicOpenFilePerm(STANDBY_SIGNAL_FILE, O_RDWR | PG_BINARY | get_syn= c_bit(sync_method), S_IRUSR | S_IWUSR); - pg_fsync(fd); - close(fd); + if (fd >=3D 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 --rwEMma7ioTxnRzrJ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlwkBCcACgkQnvQgOdby QH1zqhAAlUTXSiSSmmd0hv7yLw9fFX5K4b+j9BODvtD5fRmMhk8N3CS5h8Vp99qo 1zRGh4TVUUxY3zj4cl2ZNeX/QxMtnlrcM4927R9NilJE/ljD1R8fhQEKQT6YEa7V jJbMKHv0+Wh4wJ8CFmsJVsxRGzr0yU7OB3K2OsRYBM3mxbhVeh1jdZICFfxeVadN TWnU9Ep0hgnV7pOc8XEEMXD/yhG2w8rbZX77Av+j9Vc34opLi1e1+CO2iu7FyOq9 /rSo7C1viMuaSdRm4Kj5pN5R3fJrP9g4iAVYPLfl+02b5oBkpLh0E+D444QlFUQa 99TYdYGzqSyiiSdZvUafvuqme8zaj+CKLpwPjduuA7PcjdcMk96JwU9cEHtnlCjF wtSygfoEGknHsY1RFpG+53kr7+TOZq10QxWNeNP9bVAlSc5iu0Vcr7iVP5uiv2g8 4lRP4+LKG+O8nLhqbJmWyjMRH18hDajtdaVrfJXvmdnz/33zX43rc+GMyeMd0Vmh sXuK+CYQ0EdFhYg+Q446btblmDk/ZeKeixnVSEdZojAdGZjmKq8ac1EJBtGWw7Mz nFJrxJJr1o29HYM1rVyg7qFJ13+T2RcEv76tM4A/wk65CJ8RF9XkqqUt5YgeYQaw 3QOv2az8sQ3ncWFdlY4fMWpQSeSKNdUIBIfpAMEvm9yj5B9LBV8= =Dp0I -----END PGP SIGNATURE----- --rwEMma7ioTxnRzrJ--