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 6CD175A026F for ; Thu, 14 Mar 2024 05:25:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1710390353; bh=pgXWUeYxJT6vU+HB05zQP2P+SjLB889Ym/qpMnwzlzE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kORi3yNFcCudjSXy2vjNRSHD/HOF1Vigft25N9sbR3QUFFbGuBgervuzhewfSfZkK wR7rkus/+2ExBixlCghmdLB6HHg2oTK9FffEPPdUp7Iw5rsxA9Z8EMzJUHdhUuLLo+ nt7wBnf71A059629wbI8UuyjiI9jgXitWEFqspdNvnRU9dlmcDC7BGNGu8f4IZ97Iy u45HrzY3whz/TbOxSsOkyv9TqaUZBzCKPjkha7bvDLaEC/HVVtzUpL8/qPkAOQIC5z rY8Ud12Y5g79KmIAXXEtTVzmH9S6HekUf5kwgl4AreuEWZ42fEVfm+Jl5dYohgQvhr Q3Ge1anpmmYbQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4TwDp93cDNz4wcs; Thu, 14 Mar 2024 15:25:53 +1100 (AEDT) Date: Thu, 14 Mar 2024 15:25:40 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v2] passt, log: Call __openlog() earlier, log to stderr until we detach Message-ID: References: <20240313115810.1520728-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="kMn9gQlCNFDLAJUs" Content-Disposition: inline In-Reply-To: <20240313115810.1520728-1-sbrivio@redhat.com> Message-ID-Hash: K6IVMTZAPPZRRUNBP7PQYI2SL2HYSDON X-Message-ID-Hash: K6IVMTZAPPZRRUNBP7PQYI2SL2HYSDON 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, Paul Holzinger 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: --kMn9gQlCNFDLAJUs Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Mar 13, 2024 at 12:58:10PM +0100, Stefano Brivio wrote: > Paul reports that, with commit 15001b39ef1d ("conf: set the log level > much earlier"), early messages aren't reported to standard error > anymore. >=20 > The reason is that, once the log mask is changed from LOG_EARLY, we > don't force logging to stderr, and this mechanism was abused to have > early errors on stderr. Now that we drop LOG_EARLY earlier on, this > doesn't work anymore. >=20 > Call __openlog() as soon as we know the mode we're running as, using > LOG_PERROR. Then, once we detach, if we're not running from an > interactive terminal and logging to standard error is not forced, > drop LOG_PERROR from the options. >=20 > While at it, check if the standard error descriptor refers to a > terminal, instead of checking standard output: if the user redirects > standard output to /dev/null, they might still want to see messages > from standard error. >=20 > Further, make sure we don't print messages to standard error reporting > that we couldn't log to the system logger, if we didn't open a > connection yet. That's expected. >=20 > Reported-by: Paul Holzinger > Fixes: 15001b39ef1d ("conf: set the log level much earlier") > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > v2: Change the isatty() test to use stderr instead of stdout >=20 > log.c | 2 +- > passt.c | 14 +++++++------- > 2 files changed, 8 insertions(+), 8 deletions(-) >=20 > diff --git a/log.c b/log.c > index eafaca2..bdd31b4 100644 > --- a/log.c > +++ b/log.c > @@ -174,7 +174,7 @@ void passt_vsyslog(int pri, const char *format, va_li= st ap) > if (log_opt & LOG_PERROR) > fprintf(stderr, "%s", buf + prefix_len); > =20 > - if (send(log_sock, buf, n, 0) !=3D n) > + if (log_sock >=3D 0 && send(log_sock, buf, n, 0) !=3D n) > fprintf(stderr, "Failed to send %i bytes to syslog\n", n); > } > =20 > diff --git a/passt.c b/passt.c > index f430648..59ab501 100644 > --- a/passt.c > +++ b/passt.c > @@ -225,6 +225,8 @@ int main(int argc, char **argv) > strncpy(argv0, argv[0], PATH_MAX - 1); > name =3D basename(argv0); > if (strstr(name, "pasta")) { > + __openlog(log_name =3D "pasta", LOG_PERROR, LOG_DAEMON); > + > sa.sa_handler =3D pasta_child_handler; > if (sigaction(SIGCHLD, &sa, NULL)) { > die("Couldn't install signal handlers: %s", > @@ -237,18 +239,16 @@ int main(int argc, char **argv) > } > =20 > c.mode =3D MODE_PASTA; > - log_name =3D "pasta"; > } else if (strstr(name, "passt")) { > + __openlog(log_name =3D "passt", LOG_PERROR, LOG_DAEMON); > + > c.mode =3D MODE_PASST; > - log_name =3D "passt"; > } else { > exit(EXIT_FAILURE); > } > =20 > madvise(pkt_buf, TAP_BUF_BYTES, MADV_HUGEPAGE); > =20 > - __openlog(log_name, 0, LOG_DAEMON); > - > c.epollfd =3D epoll_create1(EPOLL_CLOEXEC); > if (c.epollfd =3D=3D -1) { > perror("epoll_create1"); > @@ -269,9 +269,6 @@ int main(int argc, char **argv) > conf(&c, argc, argv); > trace_init(c.trace); > =20 > - if (c.force_stderr || isatty(fileno(stdout))) > - __openlog(log_name, LOG_PERROR, LOG_DAEMON); > - > pasta_netns_quit_init(&c); > =20 > tap_sock_init(&c); > @@ -314,6 +311,9 @@ int main(int argc, char **argv) > if (isolate_prefork(&c)) > die("Failed to sandbox process, exiting"); > =20 > + if (!c.force_stderr && !isatty(fileno(stderr))) > + __openlog(log_name, 0, LOG_DAEMON); > + > 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 --kMn9gQlCNFDLAJUs Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmXyfDcACgkQzQJF27ox 2GejjhAAlgu9wQkLfaDcHvah7jgDHIySHyOSwvcZwGjo3PSHVYffdaEdIGJeblAa PHf/vmvb/wnbiSxOh/eSsy8HPO5HYM0UrZduD/qbaYJqfQqaVdbLL44AKUBROQ8z fsRFyN5wND1q/NyDoPV/wvlywpnpCrHMlBpa4XlUTkCzAYrd/pV78HGU0fwfiJxh 2BYLOxCPYfQ13Pjjjd+oaS2x5T6Wrt5EMLFbZHad7x6Dm/R+9P1C3fdaV+NPbCrc gUbjFqinsDL5ogUjto2ReNykkIiM860k1eN6zcrBIByejhXElDLwvsc2/gPPLRrq 9IfjtnBG1qKSfrE72cI6IAcuIGnV8Fnt0LWpkXSv9hf6zjhY6lCzaf4xdOVD+YhN aw5p3z2kMowzlw2t+tSCU7lNK+e+jAeha/YrkqdWvTQxuaGNhEWkSh/1ZmDcjw6S zxcya4rIdsx0BXsBO8W0KOGGSQzDvk/ct41YKkHF2xt8dELgcNqsw0ReuWl25/LO uMHNmpM35zBIsLFHAv/TpjkbRlDD+36h25W5+HeH2thnrr5jT0rmo7+w3iTdQcVx rnYK38SW590sisEw6LzsVtfJUZnZMJrIXKySiznci+Io48Icn4HtQkWMexKxkWmC QJ6036t0ExxLT/COCKGUnaID1dFsm7nBqfj70cJf2wIFtqEadbw= =ArYC -----END PGP SIGNATURE----- --kMn9gQlCNFDLAJUs--