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 D71AC5A004E for ; Thu, 20 Jun 2024 02:13:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1718842411; bh=hQUG50jZh3qWHZeRTKUpSnzP9aCiakV9f/vl3iUNwqo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YmQmjioiTAG5C6U+0mM10POlG0Mi8q8MnJME+aAcptSSgF3sNp8X8qJtQzcBh0nfE cEXMU6zLPA6pgCfA8dHNf8XdV2zvc3rRJBj/rIeDcRTIq+TIvGATDpVyVMZcGHWDvh 8sgCdhtmoOiV4SE7OZ2o50PJJiAIv+rZJ0s9YdfDjt1kIHWAVk2EKRYTLx3WQX8JOe dnB6TEDtEpy+W6ZOI+fR10zrFnJJQvnO2HL8z7FAAvA4jZmSn/944VR5m78veOShBz EMIWyA/5wbIxMMFREOvfQfGHIYAwOBsGuygwBzkLrf+O/fLRtKMWBmwld7pF4yfstk bhINCXM7f0hjw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4W4LYl3ldtz4wqK; Thu, 20 Jun 2024 10:13:31 +1000 (AEST) Date: Thu, 20 Jun 2024 10:12:37 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 1/6] conf, passt: Don't try to log to stderr after we close it Message-ID: References: <20240617120319.1206857-1-sbrivio@redhat.com> <20240617120319.1206857-2-sbrivio@redhat.com> <20240618080004.5fb4e355@elisabeth> <20240619101338.62a19245@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="IxENjcYmoJb1jSkL" Content-Disposition: inline In-Reply-To: <20240619101338.62a19245@elisabeth> Message-ID-Hash: EEHHCBVE7GVIG2HFR7KEWPZ2LQKWFEMZ X-Message-ID-Hash: EEHHCBVE7GVIG2HFR7KEWPZ2LQKWFEMZ 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: --IxENjcYmoJb1jSkL Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jun 19, 2024 at 10:13:46AM +0200, Stefano Brivio wrote: > On Wed, 19 Jun 2024 12:06:01 +1000 > David Gibson wrote: >=20 > > On Tue, Jun 18, 2024 at 08:00:14AM +0200, Stefano Brivio wrote: > > > On Tue, 18 Jun 2024 10:36:28 +1000 > > > David Gibson wrote: > > > =20 > > > > On Mon, Jun 17, 2024 at 02:03:14PM +0200, Stefano Brivio wrote: =20 > > > > > If we don't run in foreground, we close standard error as we > > > > > daemonise, so it makes no sense to check if the controlling termi= nal > > > > > is an interactive terminal or if --force-stderr was given, to dec= ide > > > > > if we want to log to standard error. > > > > >=20 > > > > > Make --force-stderr depend on --foreground. > > > > >=20 > > > > > Signed-off-by: Stefano Brivio =20 > > > >=20 > > > > Reviewed-by: David Gibson > > > > =20 > > > > > --- > > > > > conf.c | 3 +++ > > > > > passt.c | 2 +- > > > > > 2 files changed, 4 insertions(+), 1 deletion(-) > > > > >=20 > > > > > diff --git a/conf.c b/conf.c > > > > > index 94b3ed6..dbdbb62 100644 > > > > > --- a/conf.c > > > > > +++ b/conf.c > > > > > @@ -1693,6 +1693,9 @@ void conf(struct ctx *c, int argc, char **a= rgv) > > > > > =20 > > > > > conf_ugid(runas, &uid, &gid); > > > > > =20 > > > > > + if (!c->foreground && c->force_stderr) > > > > > + die("Can't log to standard error if not running in foreground"= ); > > > > > + > > > > > if (logfile) { > > > > > logfile_init(c->mode =3D=3D MODE_PASTA ? "pasta" : "passt", > > > > > logfile, logsize); > > > > > diff --git a/passt.c b/passt.c > > > > > index a5e2c5a..aa9648a 100644 > > > > > --- a/passt.c > > > > > +++ b/passt.c > > > > > @@ -302,7 +302,7 @@ int main(int argc, char **argv) > > > > > if (isolate_prefork(&c)) > > > > > die("Failed to sandbox process, exiting"); > > > > > =20 > > > > > - if (!c.force_stderr && !isatty(fileno(stderr))) > > > > > + if (!c.foreground || (!c.force_stderr && !isatty(fileno(stderr)= ))) =20 > > > >=20 > > > > What's the rationale for the isatty() check in any case? =20 > > >=20 > > > To implement the behaviour from the man page: > > >=20 > > > -e, --stderr > > > Log to standard error too. Default is to log to the s= ys=E2=80=90 > > > tem logger only, if started from an interactive termin= al, > > > and to both system logger and standard error otherwise.= =20 > >=20 > > Hmm.. maybe I'm getting confused reading either the man page or the > > code, but isn't that the opposite of what the code is doing? The code > > appears to be opening the log if we're *not* on an interactive terminal. >=20 > Ouch, right, this became the opposite of the original intended > behaviour from 84a62b79a2bc ("passt: Also log to stderr, don't fork to > background if not interactive") which again was implemented as a workarou= nd > for issues in the old version of the KubeVirt integration that's not used > anymore. >=20 > The swap happened in 1e49d194d017 ("passt, pasta: Introduce command-line > options and port re-mapping"), which makes me think that we should probab= ly > think of a reasonable default and meaning of --stderr regardless of the > original workaround (which is surely not needed anymore) and implement it. I agree. > Probably it would make sense to log to standard error if we're running in > foreground, unless a log file is specified. The check above would simply > become: I think logging to stderr when foreground even if we do have a logfile makes even more sense. > if (!c.foreground) >=20 > and we could accept -e, --stderr for compatibility only, but it wouldn't > do anything. >=20 > > > which was needed, in turn, because of earlier versions of passt and of > > > the KubeVirt integration where passt was running in foreground, but (= of > > > course) not attached to a terminal, and there was no option to force > > > printing to standard error. > > >=20 > > > Given that KubeVirt doesn't have a system logger, it was otherwise > > > impossible to get messages out of passt. > > >=20 > > > It's an abomination that just adds complexity now, and I don't think > > > anybody uses it that way anymore. I guess we should drop that, togeth= er > > > with qrap, in a few months from now. =20 > >=20 > > Right.. but what I'm after is the rationale for this depending on > > whether it's an interactive terminal at all. Seems to me the logical > > thing to do is to (by default) always log to stderr before > > daemonization (i.e. forever when in foreground mode), then to logfile > > and/or syslog after daemonization. Regardless of whether there's a > > tty or not. >=20 > The original rationale was that if it was started from an interactive > terminal, I didn't want the whole spam associated with it, but if it was > started from a non-interactive terminal (KubeVirt integration), that was > the only way to get messages out. >=20 > Then we had the opposite issue with KubeVirt (which is the reason why > the log file disables stderr logging): passt started in a > non-interactive terminal, but stderr logging would cause a lot of > overhead in some KubeVirt component. Again, KubeVirt can fix that with the Go equivalent of '2> /dev/null'. I don't think we should make our semantics more complex for the sake of that. --=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 --IxENjcYmoJb1jSkL Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmZzc/QACgkQzQJF27ox 2GeYJA//Z1snxs300hPr+bcz0k1lr9egozKg0bngr5xyJlTpVh0cAvWjfx7SIH/v YonkbXhz14A1AZueuEubcGCNYDyy0aL3JkIKNIlgjOlHaabnYdyHVfqgvFhV8uuE f7utKyVEjlJmMy1EwecDQAYeb/38gp/qXpV6MVpayW012CmJOjkO4MpMaFKTPej6 m4LpjhFRjQtKgbfvhPFICaJB79M/cq2zTAbPixjdCgZ9wTKbOZt9cNInvEHj+i0F ojAnOhtK8kb5GSsIL/7PQkcEzY+1GDeKfn9FqxGjNtXPo+oJ79D7Fkose3lUlBWy 8bhQF0iYiav/Fc+aWzcd3AIGDs0ME5CFXttBhWD+dgoviJQukPKHs67bKEBMc/ve jIoCwjnPmhELnq3TuLjuZbC5uur14LTdeO/XNeWxdWHj1ZEZk4ODkDQpe+T3/DPx 9PnoyznUv56123C/ZY760CMPDkd7u4vk5aCbEIOqQFvrzYhCd/7vCxDNhivSh4ov zqGDbuoXpF8e+Q49kf7CxCkK1Le/TDz9fXjsz9Am9hVXcxi3LB3/41cBSFhGhpiw KH37rvbWUNK1v0+uiz1lP068Co4+G2G2zkhuOtklD9nr1UPJNDRJQYmhB/jz5jGH B1v+gXx/ycCI8UWQivmuh7Mr90GlUkfNL1uM97WITicrga5zcu8= =Jbkb -----END PGP SIGNATURE----- --IxENjcYmoJb1jSkL--