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 665BA5A004E for ; Thu, 20 Jun 2024 02:13:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1718842411; bh=ViiLS+SEw8UpXWgmZynv26TY6GVLaVM1J0ApHlV3iMM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=S8cmjfGt/tm6hIF/bh4EGKCm0BrwoYc7iwTxPAegIJrNemdoiz3QOO00Lg9gItjy4 TP/ZBIuO4qOR4Zx/w7/2iBcCeuv8rMmKRCtoQJubod9Me3/P/dQEJT+xWB5h555kxX ihOlz5XGvmk93bkV0CgNHs+xF8Fz+o00UsOY4ylOA4i9QQF99NmmxTZbtwfbagGzz7 +tTLVXHCPUOVDesT+8ZPLLS4P3e0UZI874HGlYqezl0Hm9NZSugWbofOQQjeTuVFxn /HU5eJQDX34vdB0ezfgCX2njRIQZS9pPJqGMO5NkuQulsrbXoC+bpn7E4yjqmhW2p2 Bx2fzHSIj5cNQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4W4LYl3vTcz4wyf; Thu, 20 Jun 2024 10:13:31 +1000 (AEST) Date: Thu, 20 Jun 2024 10:12:56 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 3/6] log, passt: Always print to stderr before initialisation is complete Message-ID: References: <20240617120319.1206857-1-sbrivio@redhat.com> <20240617120319.1206857-4-sbrivio@redhat.com> <20240618080131.0fe3d7be@elisabeth> <20240619101711.2ce52091@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="IsPlL0zameZVEm0s" Content-Disposition: inline In-Reply-To: <20240619101711.2ce52091@elisabeth> Message-ID-Hash: ZIBWQR24TUSQZBV3V7SWUI677UL7Q4D3 X-Message-ID-Hash: ZIBWQR24TUSQZBV3V7SWUI677UL7Q4D3 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: --IsPlL0zameZVEm0s Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jun 19, 2024 at 10:17:21AM +0200, Stefano Brivio wrote: > On Wed, 19 Jun 2024 12:10:38 +1000 > David Gibson wrote: >=20 > > On Tue, Jun 18, 2024 at 08:01:31AM +0200, Stefano Brivio wrote: > > > On Tue, 18 Jun 2024 10:44:20 +1000 > > > David Gibson wrote: > > > =20 > > > > On Mon, Jun 17, 2024 at 02:03:16PM +0200, Stefano Brivio wrote: =20 > > > > > After commit 15001b39ef1d ("conf: set the log level much earlier"= ), we > > > > > had a phase during initialisation when messages wouldn't be print= ed to > > > > > standard error anymore. > > > > >=20 > > > > > Commit f67238aa864d ("passt, log: Call __openlog() earlier, log to > > > > > stderr until we detach") fixed that, but only for the case where = no > > > > > log files are given. > > > > >=20 > > > > > If a log file is configured, vlogmsg() will not call passt_vsyslo= g(), > > > > > but during initialisation, LOG_PERROR is set, so to avoid duplica= ted > > > > > prints (which would result from passt_vsyslog() printing to stder= r), > > > > > we don't call fprintf() from vlogmsg() either. > > > > >=20 > > > > > This is getting a bit too complicated. Instead of abusing LOG_PER= ROR, > > > > > define an internal logging flag that clearly represents that we'r= e not > > > > > done with the initialisation phase yet. > > > > >=20 > > > > > If this flag is not set, make sure we always print to stderr, if = the > > > > > log mask matches. Then, set LOG_PERROR only as we set this intern= al > > > > > flag, to make sure we don't duplicate messages. > > > > >=20 > > > > > Reported-by: Yalan Zhang > > > > > Signed-off-by: Stefano Brivio > > > > > --- > > > > > log.c | 4 +++- > > > > > log.h | 1 + > > > > > passt.1 | 3 ++- > > > > > passt.c | 17 ++++++++++------- > > > > > 4 files changed, 16 insertions(+), 9 deletions(-) > > > > >=20 > > > > > diff --git a/log.c b/log.c > > > > > index 3b5a1c6..939bb93 100644 > > > > > --- a/log.c > > > > > +++ b/log.c > > > > > @@ -49,6 +49,7 @@ int log_trace; /* --trace mode enabled */ > > > > > void vlogmsg(int pri, const char *format, va_list ap) > > > > > { > > > > > bool debug_print =3D (log_mask & LOG_MASK(LOG_DEBUG)) && log_fi= le =3D=3D -1; > > > > > + bool before_daemon =3D !(log_flags & LOG_FLAG_DAEMON_READY); = =20 > > > >=20 > > > > As in 2/6 would just a global bool be simpler than flags. > > > > =20 > > > > > bool early_print =3D !(log_flags & LOG_FLAG_CONF_PARSED); > > > > > struct timespec tp; > > > > > =20 > > > > > @@ -71,7 +72,8 @@ void vlogmsg(int pri, const char *format, va_li= st ap) > > > > > va_end(ap2); > > > > > } > > > > > =20 > > > > > - if (debug_print || (early_print && !(log_opt & LOG_PERROR))) { > > > > > + if (debug_print || early_print || > > > > > + (before_daemon && (log_mask & LOG_MASK(LOG_PRI(pri))))) { > > > > > (void)vfprintf(stderr, format, ap); > > > > > if (format[strlen(format)] !=3D '\n') > > > > > fprintf(stderr, "\n"); > > > > > diff --git a/log.h b/log.h > > > > > index 6a3224a..680baab 100644 > > > > > --- a/log.h > > > > > +++ b/log.h > > > > > @@ -10,6 +10,7 @@ > > > > > #include > > > > > =20 > > > > > #define LOG_FLAG_CONF_PARSED BIT(0) /* We already parsed logging= options */ > > > > > +#define LOG_FLAG_DAEMON_READY BIT(1) /* Daemonised, or ready in = foreground */ > > > > > =20 > > > > > #define LOGFILE_SIZE_DEFAULT (1024 * 1024UL) > > > > > #define LOGFILE_CUT_RATIO 30 /* When full, cut ~30% size */ > > > > > diff --git a/passt.1 b/passt.1 > > > > > index 3a23a43..31e528e 100644 > > > > > --- a/passt.1 > > > > > +++ b/passt.1 > > > > > @@ -99,7 +99,8 @@ terminal, and to both system logger and standar= d error otherwise. > > > > > =20 > > > > > .TP > > > > > .BR \-l ", " \-\-log-file " " \fIPATH\fR > > > > > -Log to file \fIPATH\fR, not to standard error, and not to the sy= stem logger. > > > > > +Log to file \fIPATH\fR, not to standard error (once initialisati= on is complete), > > > > > +and not to the system logger. =20 > > > >=20 > > > > IIUC when -l is set we'll log to the logfile _as well as_ stderr > > > > before we daemonize. The description above doesn't exactly contrad= ict > > > > that, but seems to imply something different. =20 > > >=20 > > > Is that because "(once initialisation is complete)" doesn't clearly > > > refer to "not to standard error"? =20 > >=20 > > Yes, or rather that it's not entirely clear it refers *only* to that > > clause and not to the "Log to file" part at the beginning. > >=20 > > > I could go with something slightly more verbose: > > >=20 > > > Log to file \fIPATH\fR, not to standard error, and not to the system > > > logger. > > >=20 > > > During initialisation phase, that is, before forking to background, > > > or before being ready for communication when running in foreground, > > > messages are always printed to standard error as well. =20 > >=20 > > Hrm... so I want to say: > >=20 > > Log to file PATH instead of to system logger. > >=20 > > Which may not be totally accurate for the current behaviour... but > > seems like it might be a sensible behaviour. That is, we typically > > log to syslog, but -l replaces it with a logfile. Regardless of > > which, under some circumstances we'll also log to stderr. >=20 > No, not really: it's not regardless of that. If the log file is given, > we don't want to log to standard error (once we're up and running) But... why? --=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 --IsPlL0zameZVEm0s Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmZzdAgACgkQzQJF27ox 2Gd+iw/9H1jS8kg604E7sdcDJVH8fyFrE6MDconFzsqNQ41IMigh4tSAQ1AlTe0Q yB4M7zagxFpdlqD4COrSMRBpBuovcX0UlnpEk9RVA2Yk1D9FM7HxVIVnZPR6KDyi TNolkCngB1TRGJBo/XT8AVevr+WPe61x0OotJIyMzct52zlMlOevB2Y5sUhBCp2K JVnB3qax+Hphx/4ET1BrH3hP+kJ7EK5lusgnQ2HIdbpNu0fJICbtP07j+0wchDQQ de1F7bgJWy0gBkKP/WndBAdEwN83rwQ7HrSFEUclGAJwyIzxddNNc3knV+5KS0Ff LxZgDXSq/wONXgtMsOjpTwQHVCRRlZt9YUlFFwCXGMRQn/doY4f6XPgwwdLs6QRQ LYXnoCDsZD64QViRARbj/40l5O0Y8yxZntlx+kbONQKHFSB2cFiLsja0A1m1vhBu 77ESut7OSUU5qBPNleweHNrkVFonjBZov6m+ou9D/YUOKqVAyLq/wWHXyyfrbsEY fL4J2pJbpPnWz4aTWwvQN95TnZFNPbBpHOITKaB68n47fv93itssXYw/YCEL5Lom 7AllYzC3cSNOoef9YMz3DJwBdPjMdc6MpO+g6NVTlC4FbhStMUnG8SnBdiHaTo+t NU8o+U0Zi1ndm0lZaS1pOio4JKs24SUGjU1EH22yBlzNYDqBJys= =uwYV -----END PGP SIGNATURE----- --IsPlL0zameZVEm0s--