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 1m8a5U-0005sr-GV for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Jul 2021 03:18:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m8a5S-0004ew-I9 for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Jul 2021 03:18:26 +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 1m8a5R-0004eo-NZ for pgsql-hackers@lists.postgresql.org; Wed, 28 Jul 2021 03:18:26 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m8a5O-0001sI-AG for pgsql-hackers@lists.postgresql.org; Wed, 28 Jul 2021 03:18:24 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 36D2B5C0139; Tue, 27 Jul 2021 23:18:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 27 Jul 2021 23:18:20 -0400 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=fm2; bh=36p3b9CKnkTGOqm/F/Mwas5079X wQh0X07MQylEmWi0=; b=qAb6UVidnK8UiS5Dg/9ln9U07GfUaNx+OeBGoWWfF2P TmyT2LyaLZvYJbLjPOeQMM68BsFwi32lvfY6mHHW3Dg3H9nwozGTB5rRgpxJlG8M GV3MVpPRKFPDpiFpxHa10t+5q/rc7q8tyAk5G4lM84p6f/7D9/EBiBmBPQpezPTg ud8ZP7vZJIQOY/5XVroT+KOpSeMSpqpex1erzukqdQ7TuNBSYUovrncIWrbgRggo OdMfYIuuy+iQmGPQJuNokIfA0spws5sAazFbFnbjm9xjmu9audG8ThDuiWWHF8WW MXSUnZh3AbMlhudjaViNLFM5TXCG7ocZcKIl26XEXFw== 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=fm3; bh=36p3b9 CKnkTGOqm/F/Mwas5079XwQh0X07MQylEmWi0=; b=M2/4iMfEuKchhex+HWNn2N ZBIsPhqyggQVHCs9S/iKkJUVGhCe+zTkgQOB7Z1kWtRtR7ctddmp0ZXwXpzzpv2X whuXCsRSaeTitzvqrErIoe3spkuLa0MteTxTdrESkpWytJA+qh/bK8gTGUm1AHze DStV7cX1VaUP6FsbUk4bSzU6UDm+yrl/0U/3Un+dIdsWKgfZzmg6syNGksrruVim Mm6cFeV770YOHj5kOGRgMMfQkOxm2ISySdGm20C31zJztKl0RLJycSkWrymKfYNZ VdTOiMBAPtubhAvFRh0B8yMaOyBssebrF4Zvjz9PfuWXybCC3U0qK1ijSYKJkKNA == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrgeekgdehhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdejtddmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredttddv necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepvdegudeuhfdtueeltedtveejheeh ieevueeigeelteegleejleeiueeiheegvefhnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihii X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 27 Jul 2021 23:18:17 -0400 (EDT) Date: Wed, 28 Jul 2021 12:18:12 +0900 From: Michael Paquier To: Alvaro Herrera Cc: Fabien COELHO , Postgres hackers Subject: Re: Some code cleanup for pgbench and pg_verifybackup Message-ID: References: <202107261935.tad2ojwemn3v@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="rod2M7KjGuY22RMv" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --rod2M7KjGuY22RMv Content-Type: multipart/mixed; boundary="78Rq8kcczyyetN1b" Content-Disposition: inline --78Rq8kcczyyetN1b Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jul 27, 2021 at 08:53:52AM +0900, Michael Paquier wrote: > On Mon, Jul 26, 2021 at 03:35:29PM -0400, Alvaro Herrera wrote: >> (In reality we cannot literally just exit(1) in pg_log_fatal(), because >> there are quite a few places that do some other thing after the log >> call and before exit(1), or terminate the program in some other way than >> exit().) >=20 > Yes, that's obviously wrong. I am wondering if there is more of > that. I have been looking at that. Here are some findings: - In pg_archivecleanup, CleanupPriorWALFiles() does not bother exit()'ing with an error code. Shouldn't we worry about reporting that correctly? It seems strange to not inform users about paths that would be broken, as that could bloat the archives without one knowing about it. - In pg_basebackup.c, ReceiveTarAndUnpackCopyChunk() would not exit() when failing to change permissions for non-WIN32. - pg_recvlogical is missing a failure handling for fstat(), as of 5c0de38.=20 - pg_verifybackup is in the wrong, as mentioned upthread. Thoughts? All that does not seem to enter into the category of things worth back-patching, except for pg_verifybackup. -- Michael --78Rq8kcczyyetN1b Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="log-fatal-exit.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/bin/pg_archivecleanup/pg_archivecleanup.c b/src/bin/pg_arc= hivecleanup/pg_archivecleanup.c index 12338e3bb2..6c3e7f4e01 100644 --- a/src/bin/pg_archivecleanup/pg_archivecleanup.c +++ b/src/bin/pg_archivecleanup/pg_archivecleanup.c @@ -151,21 +151,30 @@ CleanupPriorWALFiles(void) { pg_log_error("could not remove file \"%s\": %m", WALFilePath); - break; + exit(1); } } } =20 if (errno) + { pg_log_error("could not read archive location \"%s\": %m", archiveLocation); + exit(1); + } if (closedir(xldir)) + { pg_log_error("could not close archive location \"%s\": %m", archiveLocation); + exit(1); + } } else + { pg_log_error("could not open archive location \"%s\": %m", archiveLocation); + exit(1); + } } =20 /* diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/= pg_basebackup.c index 8f69c57380..7296eb97d0 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -1626,8 +1626,11 @@ ReceiveTarAndUnpackCopyChunk(size_t r, char *copybuf= , void *callback_data) } #ifndef WIN32 if (chmod(state->filename, (mode_t) filemode)) + { pg_log_error("could not set permissions on directory \"%s\": %m", state->filename); + exit(1); + } #endif } else if (copybuf[156] =3D=3D '2') @@ -1676,8 +1679,11 @@ ReceiveTarAndUnpackCopyChunk(size_t r, char *copybuf= , void *callback_data) =20 #ifndef WIN32 if (chmod(state->filename, (mode_t) filemode)) + { pg_log_error("could not set permissions on file \"%s\": %m", state->filename); + exit(1); + } #endif =20 if (state->current_len_left =3D=3D 0) diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup= /pg_recvlogical.c index 1d59bf3744..ebeb12d497 100644 --- a/src/bin/pg_basebackup/pg_recvlogical.c +++ b/src/bin/pg_basebackup/pg_recvlogical.c @@ -341,7 +341,10 @@ StreamLogicalLog(void) } =20 if (fstat(outfd, &statbuf) !=3D 0) + { pg_log_error("could not stat file \"%s\": %m", outfile); + goto error; + } =20 output_isfile =3D S_ISREG(statbuf.st_mode) && !isatty(outfd); } diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifyb= ackup/pg_verifybackup.c index f5ebd57a47..bb93b43093 100644 --- a/src/bin/pg_verifybackup/pg_verifybackup.c +++ b/src/bin/pg_verifybackup/pg_verifybackup.c @@ -304,6 +304,7 @@ main(int argc, char **argv) "but was not the same version as %s.\n" "Check your installation.", "pg_waldump", full_path, "pg_verifybackup"); + exit(1); } } =20 diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index c51ebb8e31..55d14604c0 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -6469,7 +6469,10 @@ main(int argc, char **argv) =20 errno =3D THREAD_BARRIER_INIT(&barrier, nthreads); if (errno !=3D 0) + { pg_log_fatal("could not initialize barrier: %m"); + exit(1); + } =20 #ifdef ENABLE_THREAD_SAFETY /* start all threads but thread 0 which is executed directly later */ --78Rq8kcczyyetN1b-- --rod2M7KjGuY22RMv Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmEAzHQACgkQnvQgOdby QH1RIg/+LgiAYuyCDAA6QfV9sx+F/ZbX3n7BMYyQ5R19OItJKC3uAFtVvhpNe98g hN7Id/4hvpm93vPoHGO4BlVLgTUnGk/Iw5X/a6crVMRKHkpTH05yhHuwu1kRuTx/ lR2FwLifHZstsX2sZDl/n2cLQD0cnei1L3yKBFLKIVH6nkbxSoHJkkrhqO6OilQB lDRRoiYa4Ku+goF+YSLraohNFwrF3j8wALnjQCG/xvc0ruVmSgsNbf1ZRIdF/O7k fhgsmcxyh8eWdVyUioPAvFKpmQ9OmAxdtiECwpgLsl26C3cd9DG15o2QLR+pY2oq 89dtVn0rD0DRDajubf3573ujAYHAxTXsUwdd9NQz/S5IcZ+JWqj3FjjztDPiJxc2 8lJ7YgqlkSphtP0IIem0r3N/2lPReumpnGzAvnasBBAeYPq1kWJqyhoUtqXN0P4u cVrbzmgcXQbw+JDjMTPJVeA6dNjnUcBJroAkqW01ohgKBYxkBnKguG6dU4rwWMRc AP6Zsq7mjvVViL/iOuj+nXyHpcgzm6nWOPPZt/KAzs1sJMXNmlsFgO+2gHfoSJ68 m8CLLCYKx4SY+osXBcrvTZ36PRdLPKbxYGULYdA5xN/BmKHtFjQN7g5wXQCP/o2b 4i6RUStHMKipOA1IURyVtvs2VGZmrazWTxSpQwLAgGNa/FROsMw= =beFp -----END PGP SIGNATURE----- --rod2M7KjGuY22RMv--