From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 18B6B5A0308 for ; Wed, 05 Jun 2024 02:00:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1717545603; bh=2jNoWtYqwRYY8352XGGFPFZjmoe8aX4o0w11xBR0P2I=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Pq1pbvtW793PeUlOUWb2/YhstLANaRb1jX6oGMqX5fq9GMBTLjdQVhKrTKU8Nf0cN 060KSxeFr+uxwsViwOucU1/y9QLZY5NGuZT6hjgJBE2D4IImPnpMHIur2jmfoO2xdv pFKH7OddKe7i/eLW6k1dhG2knN8jQ37XHCuV9ZCQcdNOpvKmabIhy7Mi5q6L7BKWDr melOUk8BUZ5mY1T/UufgYhGGXxTIoVIs3tWO3W5g+J/F+80G1qMpxfgZIK5zHXwkKd y2qNGrhxRPI2CfyJmVFWuiD9vvFjkRF99qGVN7x2JvM51LuaHInytXRinvbQIDrXrB wEmNlDmg0FOgQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Vv6z74m1jz4wyS; Wed, 5 Jun 2024 10:00:03 +1000 (AEST) Date: Wed, 5 Jun 2024 09:51:31 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 2/3] conf: Don't print usage via the logging subsystem Message-ID: References: <20240529090405.965748-1-david@gibson.dropbear.id.au> <20240529090405.965748-3-david@gibson.dropbear.id.au> <20240605004041.5c408bc8@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="21qI/xAjgQoGnyCU" Content-Disposition: inline In-Reply-To: <20240605004041.5c408bc8@elisabeth> Message-ID-Hash: 2NVQPPVXD45DND7BHBLRGBHMJDFIRCH4 X-Message-ID-Hash: 2NVQPPVXD45DND7BHBLRGBHMJDFIRCH4 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, erik.sjolund@gmail.com 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: --21qI/xAjgQoGnyCU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jun 05, 2024 at 12:40:41AM +0200, Stefano Brivio wrote: > On Wed, 29 May 2024 19:04:04 +1000 > David Gibson wrote: >=20 > > The message from usage() when given invalid options, or the -h / --help > > option is currently printed by many calls to the info() function, also > > used for runtime logging of informational messages. > >=20 > > That isn't useful: the usage message should always go to the terminal > > (stdout or stderr), never syslog or a logfile. It should never be > > filtered by priority. Really the only thing using the common logging > > functions does is give more opportunities for something to go wrong. > >=20 > > Replace all the info() calls with direct fprintf() calls. This does me= an > > manually adding "\n" to each message. A little messy, but worth it for= the > > simplicity in other dimensions. >=20 > Yes, definitely less messy than the existing implementation, I just > wonder: >=20 > > Link: https://bugs.passt.top/show_bug.cgi?id=3D90 > >=20 > > Signed-off-by: David Gibson > > --- > > conf.c | 318 ++++++++++++++++++++++++++++----------------------------- > > 1 file changed, 159 insertions(+), 159 deletions(-) > >=20 > > diff --git a/conf.c b/conf.c > > index f2a92574..31f5b197 100644 > > --- a/conf.c > > +++ b/conf.c > > @@ -706,193 +706,194 @@ static unsigned int conf_ip6(unsigned int ifi, > > /** > > * usage() - Print usage, exit with given status code > > * @name: Executable name > > + * @f: Stream to print usage info to > > * @status: Status code for exit() > > */ > > -static void usage(const char *name, int status) > > +static void usage(const char *name, FILE *f, int status) > > { > > if (strstr(name, "pasta")) { > > - info("Usage: %s [OPTION]... [COMMAND] [ARGS]...", name); > > - info(" %s [OPTION]... PID", name); > > - info(" %s [OPTION]... --netns [PATH|NAME]", name); > > - info(""); > > - info("Without PID or --netns, run the given command or a"); > > - info("default shell in a new network and user namespace, and"); > > - info("connect it via pasta."); > > + fprintf(f, "Usage: %s [OPTION]... [COMMAND] [ARGS]...\n", name); > > + fprintf(f, " %s [OPTION]... PID\n", name); > > + fprintf(f, " %s [OPTION]... --netns [PATH|NAME]\n", name); > > + fprintf(f, "\n"); > > + fprintf(f, "Without PID or --netns, run the given command or a\n"); > > + fprintf(f, "default shell in a new network and user namespace, and\n= "); > > + fprintf(f, "connect it via pasta.\n"); >=20 > I haven't checked how it looks like in the end, but in most of this > function, we use fprintf() without arguments after the format, and we > need explicit newlines anyway, so, what if we concatenate the whole > output, say: >=20 > fprintf(f, > "Without PID or --netns, run the given command or a\n" > "default shell in a new network and user namespace, and\n" > "connect it via pasta.\n" > ); >=20 > ? Fair point, I've made that change. > I used separate info() calls (or whatever they were) in the past > just because of the convenient newlines. >=20 --=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 --21qI/xAjgQoGnyCU Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmZfqGIACgkQzQJF27ox 2GfNOQ/+LitAhHqAwuZbYXJ7YJ0I4EQi68UXVy+1nxaC7NuN9vlhSYtddz/rKv+6 3TJtqEe9JgzsYUKbJ3vxygteXwgIEIYJdfojeCL+yMdH7dezmGGWMmX7/YVlmvOF KFaqSsTSK3+rFgBxnepViRQOUNtCDlrDpgSgG7ZjWxK45GNTbDFMOFDhZdo8oq6t klaVoFsb/emUVIwW4Wyzla6Jxarb2e6MuNvcacbBE4TY4vUypGxuJ8Bft0slWIPW z17zg5YhCgtnoLI+r9645ww2qKgDPevGBKsKRvmXQSCsiOfMGp+NoEQkqSajLOFW Eb+k8xCe3yCL/uRn8v1khkHVTRrnvf9h75gZRGh2EI0vZx9pSbtoowtLt0kL5Var v5StdEvPFx/YIui78KPNakYzfh2r2I4QFtUsFHaSQOepdDogf8ltiyws4itDs2wM VlYTydDJhnZ1Hgxy39gGQddJsUpM4MfHWimuWqZeL0E6cTT33BC3jB7xv0fJJzDq RPXxnpE5a+1BdlQxCpMeeq5XP4/B8PS7UR0TfjlC5nfR22XSrXmpAVrYUpBzgN58 iIRcFMe/AL/mmXq6794Sy7b5mSrDOgG3KhPDCSCiKJojBH1Wc1nzWJ8qxQ6vtcZD gjveGkGUwHhnHV0o0tHH9t0BzR04QYDvcHADjCXu1kwfvajxK+k= =J2kO -----END PGP SIGNATURE----- --21qI/xAjgQoGnyCU--