From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 010F85A026C for ; Thu, 16 Feb 2023 06:43:19 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PHP4K5WyQz4x8B; Thu, 16 Feb 2023 16:43:13 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1676526193; bh=kZYeYpwwofKG6LRsrWQLq7EueRThtk72GTsvLJ8Ktcs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nNgoSEd9z49LyIJylOaGRwt1XvpX/3iRC0ZzqgU+TsC/teAiF04h0DmrXfWelGH+t buPTEbZ3XZiqiWKg9eknYYRWdMbHzcsVZ+XRp3ceGNYihHuDwil4uhwXmqsaO60epL r6ZGm7bT61T4Sm1BERcyriX6o4Opqhb+uVKZDmfE= Date: Thu, 16 Feb 2023 16:31:39 +1100 From: David Gibson To: Laine Stump Subject: Re: [PATCH v4 2/9] add die() to log an error message and exit with a single call Message-ID: References: <20230215082437.110151-1-laine@redhat.com> <20230215082437.110151-3-laine@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="pxgqBdI8SyPGTVcN" Content-Disposition: inline In-Reply-To: <20230215082437.110151-3-laine@redhat.com> Message-ID-Hash: TYDTB5DY2DZBCCQSTIWURZLQ4I2V5WB4 X-Message-ID-Hash: TYDTB5DY2DZBCCQSTIWURZLQ4I2V5WB4 X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.3 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --pxgqBdI8SyPGTVcN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Feb 15, 2023 at 03:24:30AM -0500, Laine Stump wrote: > Almost all occurences of err() are either immediately followed by > exit(EXIT_FAILURE), usage(argv[0]) (which itself then calls > exit(EXIT_FAILURE), or that is what's done immediately after returning > from the function that calls err(). Modify the errfn macro so that its > instantiations can include exit(EXIT_FAILURE) at the end, and use that > to create a new function die() that will log an error and then > exit. >=20 > Signed-off-by: Laine Stump Reviewed-by: David Gibson > --- > log.c | 14 +++++++++----- > log.h | 1 + > 2 files changed, 10 insertions(+), 5 deletions(-) >=20 > diff --git a/log.c b/log.c > index 6dc6673..2920aba 100644 > --- a/log.c > +++ b/log.c > @@ -44,7 +44,7 @@ static char log_header[BUFSIZ]; /* File header, written= back on cuts */ > static time_t log_start; /* Start timestamp */ > int log_trace; /* --trace mode enabled */ > =20 > -#define logfn(name, level) \ > +#define logfn(name, level, doexit) \ > void name(const char *format, ...) { \ > struct timespec tp; \ > va_list args; \ > @@ -74,6 +74,9 @@ void name(const char *format, ...) { \ > if (format[strlen(format)] !=3D '\n') \ > fprintf(stderr, "\n"); \ > } \ > + \ > + if (doexit) \ > + exit(EXIT_FAILURE); \ > } > =20 > /* Prefixes for log file messages, indexed by priority */ > @@ -86,10 +89,11 @@ const char *logfile_prefix[] =3D { > " ", /* LOG_DEBUG */ > }; > =20 > -logfn(err, LOG_ERR) > -logfn(warn, LOG_WARNING) > -logfn(info, LOG_INFO) > -logfn(debug, LOG_DEBUG) > +logfn(die, LOG_ERR, 1) > +logfn(err, LOG_ERR, 0) > +logfn(warn, LOG_WARNING, 0) > +logfn(info, LOG_INFO, 0) > +logfn(debug,LOG_DEBUG, 0) > =20 > /** > * trace_init() - Set log_trace depending on trace (debug) mode > diff --git a/log.h b/log.h > index 987dc17..d4e9d85 100644 > --- a/log.h > +++ b/log.h > @@ -10,6 +10,7 @@ > #define LOGFILE_CUT_RATIO 30 /* When full, cut ~30% size */ > #define LOGFILE_SIZE_MIN (5UL * MAX(BUFSIZ, PAGE_SIZE)) > =20 > +void die(const char *format, ...); > void err(const char *format, ...); > void warn(const char *format, ...); > void info(const char *format, ...); --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --pxgqBdI8SyPGTVcN Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmPtv7UACgkQzQJF27ox 2GfQeA//cTF+bRYqT9mNVFlo+M24JpTqnk/kngZwUkqsnDuIA5pYrQYUXU1L2TXR wQxBelOLr4+aN8bIvZkbbYwPQy/+nqOGXySniLnXc8yXJ2ucSzJyxq0m4zOCaseI en+hK4g1bRrPLSw+hyLLEs7vlrNHrpj9v2Sjtt0hk3DMH6Y+I9pjf4IJETsdhUvI qXRMBGUPfRUU8vN2G8CTxvqRpl95veH6krknFTr9mg460qstuzMOZe7q2sPgUEJW kJ863D0qz3alISz4T7r+Z1r1H9sBWwgHjuOTvqfMW76z7ZP2wS2eQUIm6VkdC+H9 q+S0QhRnOOB4AZdHnN2nes2vIHYAa2mszDqhGpImh8XW98kyWJV2Y4btJv6m5F/X EGlQeqALMLPTac39T/8epk4ckKa4d+mxSzIgHiGuNlBqvi0XKaJpDVFsi5NxB+sA OaXc7kcAgn825WCdp4oCNd7Nqtdw+TXeU03Ehek7y9qw02TlGLEtTw+2SUAkZx1B 5/wc8YZCzetJyjZDzKcuT+WMMl3CeG6DG+lX7zimDeZtjCr7kLwPfUc/n+sdzIu0 eSwIIc2McdESMXCLjT5mSl6StIQZIAdgJ/3Fkjm1LSCKIRL0xzYfZTh8/6RrkcNJ XzO7QAMPY5G8bmdW4UIMPnFMNfYV+bcXgnxi5DkPv1qscizBaMw= =cs76 -----END PGP SIGNATURE----- --pxgqBdI8SyPGTVcN--