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 2E9625A004E for ; Thu, 08 Aug 2024 06:44:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1723092287; bh=roY40A+QNvbhvUwojYNYhkLvi8tJsXtiPqL7UFXRJ2Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hanq/9k+npVTSctdctz/DDzlq9Dvy/6LEcE3AXr8yN/Mugo7X4gIegieu+3Dw6BIM MtCFnAvIVwr+dQtMiBaGwJW2UiUTGTU9RhsNwSm3i/85+Spr1EIEp8VadmioRyOKs5 rBAloMJi5BgULdt866CoKCzY5lIrI0sCSo52NPmT6nD6D6jpqo4SUICeuYGQ9Mj2GY 4GuT2K1r2F2zFDkmpXUC9T3jnP6gZQaVDaXRwWD+Khkl1p8vRTxK981ppLqym1TP7c W7uzxpknmvHAZsmksp9RXqKaB9+pjje2kzejXzP1O+tWiNn9UCx6fK/OwAp29e6ivu t/rE2KnxgQ34Q== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WfZG71h4Rz4x3d; Thu, 8 Aug 2024 14:44:47 +1000 (AEST) Date: Thu, 8 Aug 2024 14:43:51 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v2] conf: Stop parsing options at first non-option argument Message-ID: References: <20240807112840.2113074-1-sbrivio@redhat.com> <20240808060228.03a33799@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="4TeOd0EsPfxGEAgr" Content-Disposition: inline In-Reply-To: <20240808060228.03a33799@elisabeth> Message-ID-Hash: JDLCMLKRMZVE7EUJ2WSVGCMW4MKQQBVM X-Message-ID-Hash: JDLCMLKRMZVE7EUJ2WSVGCMW4MKQQBVM 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: --4TeOd0EsPfxGEAgr Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Aug 08, 2024 at 06:02:28AM +0200, Stefano Brivio wrote: > On Thu, 8 Aug 2024 10:57:24 +1000 > David Gibson wrote: >=20 > > On Wed, Aug 07, 2024 at 01:28:40PM +0200, Stefano Brivio wrote: > > > Given that pasta supports specifying a command to be executed on the > > > command line, even without the usual -- separator as long as there's > > > no ambiguity, we shouldn't eat up options that are not meant for us. > > >=20 > > > Paul reports, for instance, that with: > > >=20 > > > pasta --config-net ip -6 route > > >=20 > > > -6 is taken by pasta to mean --ipv6-only, and we execute 'ip route'. > > > That's because getopt_long(), by default, shuffles the argument list > > > to shift non-option arguments at the end. > > >=20 > > > Avoid that by adding '-' at the beginning of 'optstring', and mark the > > > position of the first non-option argument (getopt_long() will now > > > return the character code 1 once we hit it), so that we can use that > > > as command to run, or as PID for the target namespace. > > >=20 > > > Reported-by: Paul Holzinger > > > Signed-off-by: Stefano Brivio =20 > >=20 > > Eh... I'm kind of ambivalent about the idea. I tend to think that > > accepting options in any position is generally expected behaviour, and > > anything programmatically adding commands to pasta should routinely > > insert a "--" (that's certainly what I do in testing code). >=20 > Sure, on the other hand it's convenient when you're quickly trying out > ip -6 route show, or some command where "--" would add 10% of typing or > so. Ok, sure. > > But, that's not a particularly strong opinion, so whatever. > >=20 > > The implementation looks more complex than necessary, though. AFAICT > > if you just add a '+' to the front of the optstring it will do exactly > > what you want without having to juggle the first_nonopt and other > > variables. >=20 > Oops, that's actually the first approach I considered, but I didn't see > any guarantee that optind would assume the expected value after the > loop. However, it does... sending v3. I don't really see how it could be anything else, after all you still need to parse the remaining non-option arguments in this case. --=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 --4TeOd0EsPfxGEAgr Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAma0TQIACgkQzQJF27ox 2Gdp0Q/+KzE0R81ZYymOgC+bdrhFPxRl2atFsXFqqsURhNO2XyZrcBJEJLiuhmm7 B5T2ZVwE/NgJZ7G4HSgnLPfNeuQsH1gHLKNBpRbH2a0CltHotj1t2sFsS/93KMK7 qsca+wNCvVdyj5RQimxpwgK4DzkG+wEMlHSMvpxgF/q0NsyRmSzqM2oEL8uSuH/v str/SfCNvyGIQb+U+xJhwgH7VeoN3/x6VaSO8e8vBcSpJKPyO31tq3OxhA69/bwO 3D18xor0/JLw9tUvYBhTPXbmRcAmpNApfv3NHWzTNTZHMI5kgY4Wyr3dU3LZYaaS /ibBct/w85DU0uE1fXEAPkgTJ56VLBInbFNgSEei6qmMC3dtUtvVUF60/vIxNd1Q 10+uUELLunJfhypA66e1EqUPMTcmfbiGvdz4mei01ZMYOdJ5DRbC9sjnQ0erQKi5 2VD92c/cnnKVrHmraEYvFrcBS/p65TSUE9SAoSUQxWleX8/qhOvYMdVSPUUlLaLB DR/alaofSaqfj0CO/jY4LoY5hKLkUdfr7WYb1OcbADkmIyYUvQi0ZQDAl0vIEj7W Io5m0wQOx9CNpai+k4hFq4gmI+HSlP4Mns1TkLv86Fp4LcYhb/Li5mtEX+FXHTyr dldPOkaCe9GST8oAcffI6ghI4J+4JMdzOO3w7PlooWw2/IdvpFU= =Om71 -----END PGP SIGNATURE----- --4TeOd0EsPfxGEAgr--