From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 32B815A0082 for ; Thu, 16 Feb 2023 06:43:17 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PHP4K5MFLz4x87; Thu, 16 Feb 2023 16:43:13 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1676526193; bh=MyrhcQsvoCpClNsmZ0ikW0WHg0m+d7zTGneZL6DLIqM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=eQsOu+c5AhdXNLIZ6hIKprEYCiE9aENfs3SiKO1vP2Y5n4tU5hcZXmmhNv9/Gqf5c CY1deQuNUsIZYKwPBMVPD3Q/5c8m4sPpbMmYIt7yzCFXSZOjRVnxClKvIXnRvq++lx r0v+RuQdCevHOXuKOCr7scV9kr9czDK8eiS6mqYI= Date: Thu, 16 Feb 2023 16:30:53 +1100 From: David Gibson To: Laine Stump Subject: Re: [PATCH v4 1/9] log to stderr until process is daemonized, even if a log file is set Message-ID: References: <20230215082437.110151-1-laine@redhat.com> <20230215082437.110151-2-laine@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="qWcoQP9EhKRqFDRt" Content-Disposition: inline In-Reply-To: <20230215082437.110151-2-laine@redhat.com> Message-ID-Hash: HAMDP7WEC3572ODEYIEPEFDPKLPP3ZKY X-Message-ID-Hash: HAMDP7WEC3572ODEYIEPEFDPKLPP3ZKY 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 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: --qWcoQP9EhKRqFDRt Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Feb 15, 2023 at 03:24:29AM -0500, Laine Stump wrote: > Once a log file (specified on the commandline) is opened, the logging > functions will stop sending error logs to stderr, which is annoying if > passt has been started by another process that wants to collect error > messages from stderr so it can report why passt failed to start. It > would be much nicer if passt continued sending all log messages to > stderr until it daemonizes itself (at which point the process that > started passt can assume that it was started successfully). >=20 > The system log mask is set to LOG_EMERG when the process starts, and > we're already using that to do "special" logging during the period > from process start until the log level requested on the commandline is > processed (setting the log mask to something else). This period > *almost* matches with "the time before the process is daemonized"; if > we just delay setting the log mask a tiny bit, then it will match > exactly, and we can use it to determine if we need to send log > messages to stderr even when a log file has been specified and opened. >=20 > This patch delays the setting of the log mask until immediately before > the call to __daemon(). It also modifies logfn() slightly, so that it > will log to stderr any time log mask is LOG_EMERG, even if a log file > has been opened. >=20 > Signed-off-by: Laine Stump Reviewed-by: David Gibson > --- > log.c | 4 ++-- > passt.c | 17 ++++++++++------- > 2 files changed, 12 insertions(+), 9 deletions(-) >=20 > diff --git a/log.c b/log.c > index 468c730..6dc6673 100644 > --- a/log.c > +++ b/log.c > @@ -66,8 +66,8 @@ void name(const char *format, ...) { \ > va_end(args); \ > } \ > \ > - if ((setlogmask(0) & LOG_MASK(LOG_DEBUG) || \ > - setlogmask(0) =3D=3D LOG_MASK(LOG_EMERG)) && log_file =3D=3D -1) {= \ > + if ((setlogmask(0) & LOG_MASK(LOG_DEBUG) && log_file =3D=3D -1) || \ > + setlogmask(0) =3D=3D LOG_MASK(LOG_EMERG)) { \ > va_start(args, format); \ > (void)vfprintf(stderr, format, args); \ > va_end(args); \ > diff --git a/passt.c b/passt.c > index d957e14..c48c2d5 100644 > --- a/passt.c > +++ b/passt.c > @@ -246,13 +246,6 @@ int main(int argc, char **argv) > if (c.stderr || isatty(fileno(stdout))) > __openlog(log_name, LOG_PERROR, LOG_DAEMON); > =20 > - if (c.debug) > - __setlogmask(LOG_UPTO(LOG_DEBUG)); > - else if (c.quiet) > - __setlogmask(LOG_UPTO(LOG_ERR)); > - else > - __setlogmask(LOG_UPTO(LOG_INFO)); > - > quit_fd =3D pasta_netns_quit_init(&c); > =20 > tap_sock_init(&c); > @@ -296,6 +289,16 @@ int main(int argc, char **argv) > exit(EXIT_FAILURE); > } > =20 > + /* Once the log mask is not LOG_EMERG, 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) > + __setlogmask(LOG_UPTO(LOG_ERR)); > + else > + __setlogmask(LOG_UPTO(LOG_INFO)); > + > if (!c.foreground) > __daemon(pidfile_fd, devnull_fd); > else --=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 --qWcoQP9EhKRqFDRt Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmPtv4cACgkQzQJF27ox 2GdOPw//emc2McSl4jnV6Jy0ECh0pxLDO1wLvZDmKf65lzC1Y1u+tK0tfBk9psdB ehzqKcChl49Dj8IkQWye00fMgVolMHBRgfSR9D8nmU21rRjOL5piSmOOmu/FIsr0 AqWm1Mkd1Wjm5WJsS1r02xuw9CHxlc8T9Xjb/dVsX58gFBiPvu46o8gxVMAWgQ3V DU5jFH5b7/Z+E7nI0eEdJLM3Oh9OC9NMMy0uHUt6E8YUnFik/KpFJS+HjbO3z8br DVJtVK86pumF7LGz61U0+SN33skgNiMfvOufQncvM1lxPPWR9PNO4oD5Nfhcu2qF 0FCejsaySx6vCZWzPtmmXbi6gR24XxLr7Ave1vVYVePKMCcfq8JSD/4Me2hgFetp tfOG0TutF6gF7qBKBJ2Z6DDs1x2167aLprhKZs99k2QRQkWl6qyQ+bs0J2WsuVF7 PXRohw/B63bB6hy4zalpR9fzQqvuCN4YwtWXaM83Eqes0aVmESNc2GeoDMnnniww gy5MAar4wcafpo5F4uDqgiojVrVaXEYJkwX8DETbovPZIglH5GNg6SOeMRnThLPB opx9jXkCH+vaKVX5V8ZljZQkz0rYUtw4FmJVFvP7MdLDqFUGkD69u8ROHzwNApEI hjnmi09dz5cf/rH8NDEcMuFic1iUpxxRPTugpxNNYTh3wMOIsUA= =i/q5 -----END PGP SIGNATURE----- --qWcoQP9EhKRqFDRt--