From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 4AD825A0051 for ; Thu, 20 Jun 2024 02:49:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1718844566; bh=sSp5+uz5x+cJEpb3zNms1ZQ4LEqj3ZrIf1K8TMgaqys=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MPKyd7kFd7VdNJur931LzGa6l0hsrlVqiePKRsGC/YJiajj/vdwzS6Ayg1Sa3/ag6 nb3tPGdHgBFiPxM9Xin+Visjehi8P/bsxI3Y4o21FKP98oW94OmoH+1o8R9Y6qtL4k AgamhhFxnFIjZtCbVCL64DHbmLcASIfzA7clBoUXxBcrhvcaZF2qnt8azWbdk5g2Cy cIG0p+HH1HwrmYS1jr/b9bqyJW50WGd4rfFbNaqdOm5qDxrt8VnLAtJseUdwDwcB6w k4ErjoLUR5w0HhcVHJ6NuS5esj56NHgWsUavkWViZPAmwwMkc+gLAahVfuFpWzrwU3 wtafcLMboFWVA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4W4MMB56T0z4wyj; Thu, 20 Jun 2024 10:49:26 +1000 (AEST) Date: Thu, 20 Jun 2024 10:45:17 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v3 5/8] log: Add _perror() logging function variants Message-ID: References: <20240619194028.2913930-1-sbrivio@redhat.com> <20240619194028.2913930-6-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ERZiqcWG2Rc7YdKD" Content-Disposition: inline In-Reply-To: <20240619194028.2913930-6-sbrivio@redhat.com> Message-ID-Hash: POBKQSGUI4BOFPIAIOXMJGDNB5BVQ3FL X-Message-ID-Hash: POBKQSGUI4BOFPIAIOXMJGDNB5BVQ3FL 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, Yalan Zhang X-Mailman-Version: 3.3.8 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: --ERZiqcWG2Rc7YdKD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jun 19, 2024 at 09:40:25PM +0200, Stefano Brivio wrote: > In many places, we have direct perror() calls, which completely bypass > logging functions and log files. >=20 > They are definitely convenient: offer similar convenience with > _perror() logging variants, so that we can drop those direct perror() > calls. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > log.c | 22 ++++++++++++++++++++++ > log.h | 21 +++++++++++++++++---- > 2 files changed, 39 insertions(+), 4 deletions(-) >=20 > diff --git a/log.c b/log.c > index 7018bda..43117c1 100644 > --- a/log.c > +++ b/log.c > @@ -78,6 +78,11 @@ void vlogmsg(int pri, const char *format, va_list ap) > } > } > =20 > +/** > + * logmsg() - vlogmsg() wrapper for variable argument lists > + * @pri: Facility and level map, same as priority for vsyslog() > + * @format: Message > + */ > void logmsg(int pri, const char *format, ...) > { > va_list ap; > @@ -87,6 +92,23 @@ void logmsg(int pri, const char *format, ...) > va_end(ap); > } > =20 > +/** > + * logmsg_perror() - vlogmsg() wrapper with perror()-like functionality > + * @pri: Facility and level map, same as priority for vsyslog() > + * @format: Message > + */ > +void logmsg_perror(int pri, const char *format, ...) > +{ > + int errno_copy =3D errno; > + va_list ap; > + > + va_start(ap, format); > + vlogmsg(pri, format, ap); > + va_end(ap); > + > + logmsg(pri, ": %s", strerror(errno_copy)); > +} > + > /* Prefixes for log file messages, indexed by priority */ > const char *logfile_prefix[] =3D { > NULL, NULL, NULL, /* Unused: LOG_EMERG, LOG_ALERT, LOG_CRIT */ > diff --git a/log.h b/log.h > index 1d6dd1d..bdeffde 100644 > --- a/log.h > +++ b/log.h > @@ -16,11 +16,18 @@ > void vlogmsg(int pri, const char *format, va_list ap); > void logmsg(int pri, const char *format, ...) > __attribute__((format(printf, 2, 3))); > +void logmsg_perror(int pri, const char *format, ...) > + __attribute__((format(printf, 2, 3))); > + > +#define err(...) logmsg( LOG_ERR, __VA_ARGS__) > +#define warn(...) logmsg( LOG_WARNING, __VA_ARGS__) > +#define info(...) logmsg( LOG_INFO, __VA_ARGS__) > +#define debug(...) logmsg( LOG_DEBUG, __VA_ARGS__) > =20 > -#define err(...) logmsg(LOG_ERR, __VA_ARGS__) > -#define warn(...) logmsg(LOG_WARNING, __VA_ARGS__) > -#define info(...) logmsg(LOG_INFO, __VA_ARGS__) > -#define debug(...) logmsg(LOG_DEBUG, __VA_ARGS__) > +#define err_perror(...) logmsg_perror( LOG_ERR, __VA_ARGS__) > +#define warn_perror(...) logmsg_perror( LOG_WARNING, __VA_ARGS__) > +#define info_perror(...) logmsg_perror( LOG_INFO, __VA_ARGS__) > +#define debug_perror(...) logmsg_perror( LOG_DEBUG, __VA_ARGS__) > =20 > #define die(...) \ > do { \ > @@ -28,6 +35,12 @@ void logmsg(int pri, const char *format, ...) > exit(EXIT_FAILURE); \ > } while (0) > =20 > +#define die_perror(...) \ > + do { \ > + err_perror(__VA_ARGS__); \ > + exit(EXIT_FAILURE); \ > + } while (0) > + > extern int log_trace; > extern bool log_conf_parsed; > extern bool log_daemon_ready; --=20 David Gibson (he or they) | 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 --ERZiqcWG2Rc7YdKD Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmZze5wACgkQzQJF27ox 2GfY5hAAhtfNZBtewCKlEYvDDncpa7Q3UTuqgwfLaHb6YWGGzw88glvB9sb/fnSE d6J8qqHYvKnQ2TXA4UT4BQsYC7KFBXUJESx67AJLujE4tkWJaGPs8PZo56bOTHQQ GAFwd/SvCtTJQz5GOTs9Z2ok8pD9BlH44uSJYAmVMD970cTRaKG5AmKUpDGm1U0i WGfNQb9+yi9cqovDgT7X1vlcWhkLvN3PHeL0HL8PrUdUNByLOJXchIHZG00MUye3 oGIzkssFMM17hy1xlvzD8dfUCDKAtu5Ttmnqp2qaTPzY6UJ/9ZayZqFyRIt6qWSj uqvW7/BRqFDcnXrbQ6YMB1CBLT5o5hby+Z7hNZ+mJ7W5YgTgpED9F+JMss6duhaB QkNqhW2ocAoOql4MS/INkDnR2xQoYBWliNk9G4hl8mL9hTMXM4+3Anw3KgQGHAqc TijRB79NJXHwtJcnavaINUJpWl8UUwUpImQ/PirHkc5kfYvsasbajN3qmulT2xBo BfAfwnBR3vnOaVB6pJvDp2aCUd+aBVZ1dwLiW1GaG+YTKdwc2nYuI8gV+J/y2LJG oTjGBUI8sH5b8eOTHKOCt1QK0wpLaF/UDWsAh9KycitvWLQr9KqhtSpaLe4nJjQ8 bO+zKR0SpyBewLHXedGxiGE/PgFl/h47X1J9A6RFdhatDM8mgHA= =nZ/N -----END PGP SIGNATURE----- --ERZiqcWG2Rc7YdKD--