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 9E6F55A0051 for ; Tue, 18 Jun 2024 02:52:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1718671915; bh=OIlYcEnE+hiliSt/73zTmBOB8qxQzxcIj+r04y1zSgM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AEY1KRpm52Qhohv73+0SmwHZxnRWi5e8fIg3C6//WWt//mlIiWBh0ffzl9kbeZsS2 J2PmRW5jVG+1CLW5UXx7I6zfm0TPLJnYmauPruE2YB2HN/9hVsUKoRUmlXGgWukJE1 CYlk3MZhBOK8S4zBSZaHEOzyPvUBFUGbvwFesDCk3oM3ys7rdIRoTNUb/s+X8BjJ1m tKIeeTuvcOxb9Tc7Hu02IWBW0fgfq/aXXv72D/yfktSn3B5pQf/IVhZce+k0/81nrJ PUkBBY/5sgfd9jHHfMaqwsjaZUUAYwAqDDVGXCWJpypHxqyIgOyPAu6NVzKZia0AyJ QkjnuDqPspPPg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4W37Vz28W1z4x12; Tue, 18 Jun 2024 10:51:55 +1000 (AEST) Date: Tue, 18 Jun 2024 10:46:36 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 4/6] log: Add _perror() logging function variants Message-ID: References: <20240617120319.1206857-1-sbrivio@redhat.com> <20240617120319.1206857-5-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="TOE+sdwduqTwOqVO" Content-Disposition: inline In-Reply-To: <20240617120319.1206857-5-sbrivio@redhat.com> Message-ID-Hash: ODUQONXTUQ2YDTN5KGAO5CN2EZPEYWJL X-Message-ID-Hash: ODUQONXTUQ2YDTN5KGAO5CN2EZPEYWJL 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: --TOE+sdwduqTwOqVO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jun 17, 2024 at 02:03:17PM +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 Hm, for anything bigger than like a screenful of code, I generally find an explicit message with strerror(errno) more useful than perror() or equivalents, but I guess if you think these are useful. > --- > log.c | 21 +++++++++++++++++++++ > log.h | 21 +++++++++++++++++---- > 2 files changed, 38 insertions(+), 4 deletions(-) >=20 > diff --git a/log.c b/log.c > index 939bb93..6764b2b 100644 > --- a/log.c > +++ b/log.c > @@ -80,6 +80,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; > @@ -89,6 +94,22 @@ 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, ...) > +{ > + va_list ap; > + > + logmsg(pri, "%s: ", strerror(errno)); > + > + va_start(ap, format); > + vlogmsg(pri, format, ap); > + va_end(ap); > +} > + > /* 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 680baab..5be0be9 100644 > --- a/log.h > +++ b/log.h > @@ -19,11 +19,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 { \ > @@ -31,6 +38,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; > void trace_init(int enable); > #define trace(...) \ --=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 --TOE+sdwduqTwOqVO Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmZw2OsACgkQzQJF27ox 2Gd1Bg/8DiaIX4fYB1XiIJppfnMPYLsrNyRH4HNRudG0NrJRzTTWqjgSBcKe0hS5 I7e/NAUmKW9vkUiEbJ7uCkwjk0e32qyuGIKlZPrbDAMz3MmckHTxkg7DgGjT+FlL FdBmwW3kP4DPaeuZrNiaWlb6+Udoxdrmv7H2OMWJjUddS+elBPYxahOk40Ucws9S YVtbVXjJbCKJ9dp4XEIknUSoXxIwUTuUPZh8DSvDB/gzVAquf5gE2L1QZ9JhtOqF 9PZEg9If7HgxOPg4Pb2IzBanYvq488zWQ1TJzyvLSQanungYrjyfgApjtzs9Iy07 FVs2LjNx09+nTTHWsavIPqnRaV2WeQW2ZMz+0a0F3gi8Fx4ONCVoHh9/hmjIOWXp fXVEr5IMeId6eyBPs8gw9J/XWaTbEEvG7MTvLYKJkPXLXvX7IwvE3Jqf7LQ3gars AE6uVqfCROT8RZUxUubsTo/13JG/HTINamzCpMsU08vFblFnCO8eIlQF5uB5Ie4M ZrhyPwgfzAa2sYrNbAL10t4YovU/vCyNOlbrxkDPnXR3Qh2F83ddWV99pnpBxzyW UijEO/G0trpdXfzm9mJ0Kx/bwoVNYUncGSaFxSfBuS19ld2+yaceemTQtgMnNBNB UPWFfHEvmDTww/7RcoqPq/7IGiXzUvFuM1T1gAy3rj0GowsXImg= =KyCo -----END PGP SIGNATURE----- --TOE+sdwduqTwOqVO--