From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 7250C5A0082 for ; Mon, 13 Feb 2023 04:38:38 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PFVRr5G86z4x8H; Mon, 13 Feb 2023 14:38:32 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1676259512; bh=eJF/ti/c/+pU5bC7cjxYXy4eGC355KFTkYH0MopsK5g=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=l2RNGsNzVTwO3UOpc+l5SiJLNuRcdG2zoRh7kBUBjsDSTv0QMarp03+gU4PXKqvlD jgjEuKES/NMSkCWdUI+LtrnwXUCYE/LXSt75zxIus99L6ssjBGQtXjhG9YH4iYjI9p 3T/bYs2YzbCFFMUTLmAyrOx2IaiLfKkQbGkt9Hc0= Date: Mon, 13 Feb 2023 14:22:33 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v2 2/9] add errexit() to log an error message and exit with a single call Message-ID: References: <20230208174838.1680517-1-laine@redhat.com> <20230208174838.1680517-3-laine@redhat.com> <20230209184532.38ef1d4b@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="+aAqmm7UltZdly+9" Content-Disposition: inline In-Reply-To: <20230209184532.38ef1d4b@elisabeth> Message-ID-Hash: A3MYXFOZUJRJU4OWIWS6SCJNIWIEFSO4 X-Message-ID-Hash: A3MYXFOZUJRJU4OWIWS6SCJNIWIEFSO4 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: Laine Stump , passt-dev@passt.top, laine@laine.org 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: --+aAqmm7UltZdly+9 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Feb 09, 2023 at 06:45:32PM +0100, Stefano Brivio wrote: > On Wed, 8 Feb 2023 12:48:31 -0500 > Laine Stump wrote: >=20 > > 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 errxit() that will log an error and then > > exit. > >=20 > > Signed-off-by: Laine Stump > > --- > > log.c | 13 ++++++++----- > > log.h | 1 + > > 2 files changed, 9 insertions(+), 5 deletions(-) > >=20 > > diff --git a/log.c b/log.c > > index 0ab0adf..4956914 100644 > > --- a/log.c > > +++ b/log.c > > @@ -45,7 +45,7 @@ static char log_header[BUFSIZ]; /* File header, writt= en 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; \ > > @@ -76,6 +76,8 @@ void name(const char *format, ...) { \ > > if (format[strlen(format)] !=3D '\n') \ > > fprintf(stderr, "\n"); \ > > } \ > > + if (doexit) \ >=20 > A blank line before this would make it more consistent. >=20 > > + exit(EXIT_FAILURE); \ > > } > > =20 > > /* Prefixes for log file messages, indexed by priority */ > > @@ -88,10 +90,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(errexit, LOG_ERR, 1) > > +logfn(err, LOG_ERR, 0) > > +logfn(warn, LOG_WARNING, 0) > > +logfn(info, LOG_INFO, 0) > > +logfn(debug, LOG_DEBUG, 0) > > =20 > > /** > > * log_go_daemon() - tell logging subsystem that the process has been > > diff --git a/log.h b/log.h > > index a57c777..ed19415 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 errexit(const char *format, ...); > > void err(const char *format, ...); > > void warn(const char *format, ...); > > void info(const char *format, ...); >=20 > Other than that, this looks good to me. LGTM. Personally I like to call such functions "die()". --=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 --+aAqmm7UltZdly+9 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmPprPIACgkQzQJF27ox 2GdlZA/7BKKb3S8K5RfsQDK6fsEoDsa6R/yrQkCxXtrLeK0pObmX4SZt343uyGUD P8CBT696uUcdDr3Pcf+NWOxZg138O4G98m3Wwh2s4lPgwUyy3uH1FF1g7N/ZsTkK qC0dTgSMOnjD/QU3EhJNosHxF/lmlbO6iEOfwXpmMD/f9XZwon0V0U9DFGS4ctTT 3ADybEYZnrDHL0rfgn/O7LmtaJESiky1MTLSK5M7LKmoPLq0k+V3DrmBzIIUGMiG mBLXJ8F0NxN6TW4VQaSj8YREYe69bE82BNZhHIq6nzzFMCRBlSfaKV7U+Jfv3m1v f2oYEpmPys8GRHXJsLkswpJr8p0IJ/gnc2IkVDiW/k3cyjWSLgv5gvVZnCY7a1Qd UpjsJEOQ4XM4N0IIBubo7NRqmJimBc8xY2JVWeyF6BfjyHYmtbSRHrs/PT2sLLZn 9rEbrAkcOBxVmTkXNIMPl+jik4indCm8PvaVIykRGYL1jNIJ4L2FMz6qEcCdhtWv xycceoL4MqTauNwKP+55iVGWVpiMdc7tMbG+JGUbrlVnx6ULBi0aUlFuqfSkP7p9 jWfUS9NpXJTSDpJ618fqTOhwimfqfZ69DSsNEXDi26h30/9P+WCozEnNZeTggJNJ Zs/qPNisROG268AOAjcUX7126qvZm3jXgZoNIhCSNLiCal8pWQs= =ns7l -----END PGP SIGNATURE----- --+aAqmm7UltZdly+9--