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 BE9625A0082 for ; Thu, 16 Feb 2023 06:44:58 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PHP6J66Gxz4x5W; Thu, 16 Feb 2023 16:44:56 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1676526296; bh=t1VEgEQLymh3xCHHQ8Gd7aDLwjSKC/xvaezKgbWfLPQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Dov5BCvqVFacWIxf6F7E7olScVZ6SatmE/8qWCR+SiAXbb9ztcd+ORJVsA7uHCAo6 TB6yOrfgGIlPzM+g8sgUSwJPMpVNU56MhsnFOeMav0dnfF+cNc2ccCntzrzXzRgDaQ INsKQHJVAoGlQ56TkqvhhU2zJqEuE4dhc5wRwLMg= Date: Thu, 16 Feb 2023 16:44:50 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH] log: Don't duplicate messages on stderr before daemonising Message-ID: References: <20230215115529.2157137-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="vqiK8OBxg72Al8sq" Content-Disposition: inline In-Reply-To: <20230215115529.2157137-1-sbrivio@redhat.com> Message-ID-Hash: 2IMTQEUZW7G4POEMWVGNSL3Z65CGIE7Q X-Message-ID-Hash: 2IMTQEUZW7G4POEMWVGNSL3Z65CGIE7Q 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, Laine Stump 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: --vqiK8OBxg72Al8sq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Feb 15, 2023 at 12:55:29PM +0100, Stefano Brivio wrote: > Now that logging functions force printing messages to stderr before > passt forks to background, we'll have duplicate messages when running > from an interactive terminal, or if --stderr is passed, because at > some point we set LOG_PERROR in our __openlog() wrapper. >=20 > We could defer setting LOG_PERROR, but that would change option > semantics in other, unexpected ways. We could force calling > passt_vsyslog() as long as the mask is set to LOG_EMERG, but that > complicates the logic in logging functions even further. >=20 > Go the easy way for now: don't force printing to stderr with > LOG_EMERG if LOG_PERROR is already set. We should seriously consider a > rework of those logging functions at this point. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > This applies on top of Laine's series. >=20 > log.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) >=20 > diff --git a/log.c b/log.c > index 785bc36..f23e8ef 100644 > --- a/log.c > +++ b/log.c > @@ -44,6 +44,8 @@ static char log_header[BUFSIZ]; /* File header, written= back on cuts */ > static time_t log_start; /* Start timestamp */ > int log_trace; /* --trace mode enabled */ > =20 > +#define BEFORE_DAEMON (setlogmask(0) =3D=3D LOG_MASK(LOG_EMERG)) > + > #define logfn(name, level, doexit) \ > void name(const char *format, ...) { \ > struct timespec tp; \ > @@ -56,8 +58,7 @@ void name(const char *format, ...) { \ > tp.tv_nsec / (100L * 1000)); \ > } \ > \ > - if ((LOG_MASK(LOG_PRI(level)) & log_mask) || \ > - setlogmask(0) =3D=3D LOG_MASK(LOG_EMERG)) { \ > + if ((LOG_MASK(LOG_PRI(level)) & log_mask) || BEFORE_DAEMON) { \ > va_start(args, format); \ > if (log_file !=3D -1) \ > logfile_write(level, format, args); \ > @@ -67,7 +68,7 @@ void name(const char *format, ...) { \ > } \ > \ > if ((setlogmask(0) & LOG_MASK(LOG_DEBUG) && log_file =3D=3D -1) || \ > - setlogmask(0) =3D=3D LOG_MASK(LOG_EMERG)) { \ > + (BEFORE_DAEMON && !(log_opt & LOG_PERROR))) { \ > va_start(args, format); \ > (void)vfprintf(stderr, format, args); \ > va_end(args); \ --=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 --vqiK8OBxg72Al8sq Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmPtwswACgkQzQJF27ox 2GfcDBAAqCPjjEu34WwTLlCrz2pEiHq04mSKyf4kcss0H8AsrpxsxW0w+OUdkLrd 2oU6L/Lq9dd/l95xO2dF3zmOOC81eKT98VkHfb5Bv2fx3ZuyrmxFmrQi+PhbyfWa QHPl+uNQsYRT+XWGqBP7o753mPlxzx6ICdLnxoEtMyzyY4dMD7Upd/lc+IduUUOB 5RkgSKc5EM9EcwytITHM/8gbBdQjNffGoopEFPzne48ortD1qbpqSsP2CHGPGRpW 09Wsg9HKz3NUASrsK6M+Djic6/V/yD8rlhey3UOaZQvU0ZrVQeB+z30xaT19Dzxe RFLwB6HyOZi10dhaIZcYzktpB/WzkEcWRsnEB30TCmneMuTdazZnGcZEzPiaF8/Y YLMegY+D4SGkr6SVCIdTzHAse6S1SB/h9zIpGcRNoDVkVHBCIJH6vQEXzn306RkN Ev/Z+QqPS0xH51ZnjQNIbCuusldf0PhEaZQonvcYGNvG65PF5YjLUZ7ARYbadYxg yxnkumF9KKJkV4yhjnwmY7f6Ga7mr5gkE8X6VZTX3pGGLTN12fmOjq2lTXz+0vau tamW3xkiaX1iDRVl7fXoRRiBkT4XjH7J0i7o7RfXftPML2brgrpkNEYHNpWVqZHD hfV0VRXRozgZulMCoG9yxcLd451LVpeZh2BV4DIqqbKUO37ri10= =8BTC -----END PGP SIGNATURE----- --vqiK8OBxg72Al8sq--