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 88A555A0262 for ; Mon, 5 Jun 2023 04:19:26 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4QZHNm0tBsz4x4S; Mon, 5 Jun 2023 12:19:20 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1685931560; bh=M0up/4XhlqMs8EuzhD5M8TQ9ZT9AbGwXUNmAbetGRzc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jaOL1ueIOQtTvA3UOVRBc6dYZ1LnMRBmgU4rnMeCEAYlrApVpxBe3w63FsY14IZkl sihhXo9Nsa1KKj7LEam9+8fYcK6Xp33vfbspPW9BIktO8HdjTl8xK6Jd8kAdDfX+Dl aEtO1Pn8oMS9OQZVAvsTbobi8HEky2xuahmBl+ms= Date: Mon, 5 Jun 2023 12:17:35 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH] conf, log: On -h / --help, print usage to stdout, not stderr Message-ID: References: <20230604055001.619958-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Az0mRQx9QGKXw3SY" Content-Disposition: inline In-Reply-To: <20230604055001.619958-1-sbrivio@redhat.com> Message-ID-Hash: IVRDNEPDARREZ75SEEMXCOPHR3KTFDL2 X-Message-ID-Hash: IVRDNEPDARREZ75SEEMXCOPHR3KTFDL2 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 =?iso-8859-1?Q?Sj=F6lund?= 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: --Az0mRQx9QGKXw3SY Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Jun 04, 2023 at 07:50:01AM +0200, Stefano Brivio wrote: > Erik suggests that this makes it easier to grep for options, and with > --help we're anyway printing usage information as expected, not as > part of an error report. >=20 > Reported-by: Erik Sj=F6lund > Link: https://bugs.passt.top/show_bug.cgi?id=3D52 > Signed-off-by: Stefano Brivio Clunky way to accomplish it, but it'll do for now. Reviewed-by: David Gibson > --- > conf.c | 4 +++- > log.c | 8 +++++--- > log.h | 1 + > 3 files changed, 9 insertions(+), 4 deletions(-) >=20 > diff --git a/conf.c b/conf.c > index ffff235..9eb6992 100644 > --- a/conf.c > +++ b/conf.c > @@ -1630,8 +1630,10 @@ void conf(struct ctx *c, int argc, char **argv) > case 'U': > /* Handle these later, once addresses are configured */ > break; > - case '?': > case 'h': > + log_to_stdout =3D 1; > + /* Falls through */ > + case '?': > default: > usage(argv[0]); > break; > diff --git a/log.c b/log.c > index 3a3d101..63d7801 100644 > --- a/log.c > +++ b/log.c > @@ -43,17 +43,19 @@ static char log_header[BUFSIZ]; /* File header, writt= en back on cuts */ > =20 > static time_t log_start; /* Start timestamp */ > int log_trace; /* --trace mode enabled */ > +int log_to_stdout; /* Print to stdout instead of stderr */ > =20 > #define BEFORE_DAEMON (setlogmask(0) =3D=3D LOG_MASK(LOG_EMERG)) > =20 > #define logfn(name, level) \ > void name(const char *format, ...) { \ > + FILE *out =3D log_to_stdout ? stdout : stderr; \ > struct timespec tp; \ > va_list args; \ > \ > if (setlogmask(0) & LOG_MASK(LOG_DEBUG) && log_file =3D=3D -1) { \ > clock_gettime(CLOCK_REALTIME, &tp); \ > - fprintf(stderr, "%lli.%04lli: ", \ > + fprintf(out, "%lli.%04lli: ", \ > (long long int)tp.tv_sec - log_start, \ > (long long int)tp.tv_nsec / (100L * 1000)); \ > } \ > @@ -70,10 +72,10 @@ void name(const char *format, ...) { \ > if ((setlogmask(0) & LOG_MASK(LOG_DEBUG) && log_file =3D=3D -1) || \ > (BEFORE_DAEMON && !(log_opt & LOG_PERROR))) { \ > va_start(args, format); \ > - (void)vfprintf(stderr, format, args); \ > + (void)vfprintf(out, format, args); \ > va_end(args); \ > if (format[strlen(format)] !=3D '\n') \ > - fprintf(stderr, "\n"); \ > + fprintf(out, "\n"); \ > } \ > } > =20 > diff --git a/log.h b/log.h > index 3aab29d..a17171a 100644 > --- a/log.h > +++ b/log.h > @@ -22,6 +22,7 @@ void debug(const char *format, ...); > } while (0) > =20 > extern int log_trace; > +extern int log_to_stdout; > void trace_init(int enable); > #define trace(...) \ > do { \ --=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 --Az0mRQx9QGKXw3SY Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmR9RbkACgkQzQJF27ox 2GcOcQ//Vy/9ZZBewpx3ErnwNYF5H+US1IybOySkugOx/2zG8rMeBUIj1ren425W S/j2HPxfRurkXPwHnYFg8BZTOudonQ4uR2YVfuPABp+241wMEfAEHNNtGooec9aU njKcOLg0qzcYOqnrdjkEvO0jQ/BIOpVzs7QonAZJdRCq8q2OzVqRFjpcUHkFaC0q iOaROmkqFqjVbyH8mejkDa5nNJy3paUSSXX+cOAqMxc3j4VH7/HSa9udOeLGOkeV hPdimYCIyIH6jS/wI9ENrBG//UmgKd+oeeB+ty+/Rra+k90h/bc+TOAJev6v1kwC Tg1LzAanR03gH+61cNficf7Z3KYMg7+0tZBpJGBxJz6YClSbTrQz/+FYW+6DiFzI ROezMQsGAI6Rz3SuLTPsnPhL1PREK2IxR+XUSlVZ/UZPhDWY9U/i43WqdM3cN018 hPjr5tU4AGvGoQYZhhODEJq8sKP2D9dUfi4NQ1ut4yijzIFwYnh92DdmH9+qaZjy JtFww8sNdDc9asQsaRqtdd5q+6MnNayw8Y38AQ49wef7AH5l4VEeqjldOYJLbuEA ZTgJGjPNVn92PXjcuGHEUyGVh+QlMjjAcCo+PXswe7ttHeU4pxOyfTwyFeC1pMS3 GFnu+rXiE7prchgbiKNjVNnkGFzZmqbwP+uLUFlVYbLkfWZkv80= =Irfw -----END PGP SIGNATURE----- --Az0mRQx9QGKXw3SY--