From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 2F6AC5A004E for ; Thu, 20 Jun 2024 02:49:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1718844566; bh=HSV8luTx9jhZ32KbD7+0RXcBmeIdESEanFgpAkVtTOw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PVg49DHBMRc7RoD8/yEeWgEWT5j88ZDL/Hc0Kvev7+kv6jOFQXukadNdvmydIGQ5V 9a+mWxVQVm7Uxqt9ndNyRIwF3tNGGJyEzz9ztlCsWMT6ALGVuzrK1jMdegCJhH3I+N /iwSlRbmfIoC0mt2R4uYBjP0PhJ0lXzs2GqaIzK1JKwHG5La5Fbwp2VNhctb4sWkud EHOziU2RhVAkaLKvFZ0vCvFpq5skQ4OfhwXfwR1BFkA4Nvbj10K9ZeNQdZdCfsPnpv hRfpXMFPL3DIi2mMEE252gt0QyzyNhFT7Efsy0p9R+Q5wV7WbeCntyzpDFD+T7FwKQ veMPK+3Nxlupg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4W4MMB4tJDz4wyg; Thu, 20 Jun 2024 10:49:26 +1000 (AEST) Date: Thu, 20 Jun 2024 10:33:26 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v3 3/8] conf, log: Instead of abusing log levels, add log_conf_parsed flag Message-ID: References: <20240619194028.2913930-1-sbrivio@redhat.com> <20240619194028.2913930-4-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="M/ZNrJlKTdijgwRv" Content-Disposition: inline In-Reply-To: <20240619194028.2913930-4-sbrivio@redhat.com> Message-ID-Hash: TYU553YTASQJGYLN5FJE533SMMVZGIQ7 X-Message-ID-Hash: TYU553YTASQJGYLN5FJE533SMMVZGIQ7 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: --M/ZNrJlKTdijgwRv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jun 19, 2024 at 09:40:23PM +0200, Stefano Brivio wrote: > We currently use a LOG_EMERG log mask to represent the fact that we > don't know yet what the mask resulting from configuration should be, > before the command line is parsed. >=20 > However, we have the necessity of representing another phase as well, > that is, configuration is parsed but we didn't daemonise yet, or > we're not ready for operation yet. The next patch will add that > notion explicitly. >=20 > Mapping these cases to further log levels isn't really practical. > Introduce boolean log flags to represent them, instead of abusing > log priorities. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > conf.c | 5 ++--- > log.c | 12 +++++------- > log.h | 3 +++ > 3 files changed, 10 insertions(+), 10 deletions(-) >=20 > diff --git a/conf.c b/conf.c > index 9f869f5..726efaf 100644 > --- a/conf.c > +++ b/conf.c > @@ -1687,9 +1687,6 @@ void conf(struct ctx *c, int argc, char **argv) > logfile, logsize); > } > =20 > - /* Once the log mask is not LOG_EARLY, we will no longer log to stderr > - * if there was a log file specified. > - */ > if (c->debug) > __setlogmask(LOG_UPTO(LOG_DEBUG)); > else if (c->quiet) > @@ -1697,6 +1694,8 @@ void conf(struct ctx *c, int argc, char **argv) > else > __setlogmask(LOG_UPTO(LOG_INFO)); > =20 > + log_conf_parsed =3D true; /* Stop printing everything */ > + > nl_sock_init(c, false); > if (!v6_only) > c->ifi4 =3D conf_ip4(ifi4, &c->ip4, c->mac); > diff --git a/log.c b/log.c > index aaf2beb..05b7f80 100644 > --- a/log.c > +++ b/log.c > @@ -30,12 +30,9 @@ > #include "util.h" > #include "passt.h" > =20 > -/* LOG_EARLY means we don't know yet: log everything. LOG_EMERG is unuse= d */ > -#define LOG_EARLY LOG_MASK(LOG_EMERG) > - > static int log_sock =3D -1; /* Optional socket to system logger */ > static char log_ident[BUFSIZ]; /* Identifier string for openlog() */ > -static int log_mask =3D LOG_EARLY; /* Current log priority mask */ > +static int log_mask; /* Current log priority mask */ > static int log_opt; /* Options for openlog() */ > =20 > static int log_file =3D -1; /* Optional log file descriptor */ > @@ -45,12 +42,13 @@ static size_t log_cut_size; /* Bytes to cut at start= on rotation */ > static char log_header[BUFSIZ]; /* File header, written back on cuts */ > =20 > static time_t log_start; /* Start timestamp */ > + > int log_trace; /* --trace mode enabled */ > +bool log_conf_parsed; /* Logging options already parsed */ > =20 > void vlogmsg(int pri, const char *format, va_list ap) > { > bool debug_print =3D (log_mask & LOG_MASK(LOG_DEBUG)) && log_file =3D= =3D -1; > - bool early_print =3D LOG_PRI(log_mask) =3D=3D LOG_EARLY; > struct timespec tp; > =20 > if (debug_print) { > @@ -60,7 +58,7 @@ void vlogmsg(int pri, const char *format, va_list ap) > (long long int)tp.tv_nsec / (100L * 1000)); > } > =20 > - if ((log_mask & LOG_MASK(LOG_PRI(pri))) || early_print) { > + if ((log_mask & LOG_MASK(LOG_PRI(pri))) || !log_conf_parsed) { > va_list ap2; > =20 > va_copy(ap2, ap); /* Don't clobber ap, we need it again */ > @@ -72,7 +70,7 @@ void vlogmsg(int pri, const char *format, va_list ap) > va_end(ap2); > } > =20 > - if (debug_print || (early_print && !(log_opt & LOG_PERROR))) { > + if (debug_print || (!log_conf_parsed && !(log_opt & LOG_PERROR))) { > (void)vfprintf(stderr, format, ap); > if (format[strlen(format)] !=3D '\n') > fprintf(stderr, "\n"); > diff --git a/log.h b/log.h > index e0aab5a..3dab284 100644 > --- a/log.h > +++ b/log.h > @@ -6,6 +6,7 @@ > #ifndef LOG_H > #define LOG_H > =20 > +#include > #include > =20 > #define LOGFILE_SIZE_DEFAULT (1024 * 1024UL) > @@ -28,6 +29,8 @@ void logmsg(int pri, const char *format, ...) > } while (0) > =20 > extern int log_trace; > +extern bool log_conf_parsed; > + > void trace_init(int enable); > #define trace(...) \ > do { \ --=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 --M/ZNrJlKTdijgwRv Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIyBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmZzeNUACgkQzQJF27ox 2GdUBQ/3fXucvhM9XJKrwELDWeOqkMEdGkKDPtHVwGAaykCGB538VrLhX/KyFi3l szDWJ8ck/lAPHvtjPV5sXpEVSX40JyB3bMg2WNw32NKZQqqO8iWxqGsf3UpbDIjo ScvGQ6zcjcVEGI5BwggHl3r96T3hWuqK0HFALUCY454gBFOzqhM4QRaMlLgqf2Kf siYW8mqIoe8EswBZa5Ttd1dRVXcHU1MYHeINPmynG/EkL52dtTaG7W/9k/SbJcRD rrr5yD5jyTjUzW4hnyaqieZ+04WsOrq51qs6I7BSSGUePmNruBwxLjk58D2Or2ty nJnluCXaVGwhyqG0gHkL0o4EAE0eEhlRGcerjj36QbEwKsHF2BYCbwfV7egu1WBD SVRt6jNkQ5sRR3CgsdKrKRe64z6aM50PBlz0knqnaCsAakSs+NVDHgPE74I0FAV2 79AwFalmyMOw6dgQePUt18nTfKIhkybspHY7LL6B3CXZCSOrhzR+spYpDibyoC54 83EjTgy58/pp/Wu1hjL04vXqGmXCt95kbumwii7NLkBLUemsSGYeYoMfdiUeiCeo qT/fRpFFR/hTYixtlk5a6Vs9BYxnUJzpRtz0H60k6Vt+/ZDzhqpblX7YkLBMdQTV 21a84zywTgmYDsP+04+2+k82DaVTAYhu9JjnaHmzuZz1AJvKTw== =Fez7 -----END PGP SIGNATURE----- --M/ZNrJlKTdijgwRv--