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 72A2E5A004F for ; Thu, 08 Aug 2024 02:57:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1723078651; bh=U9mTyoUY2YdPhkAFWDRu3CK8rAZXTzjHwXjG/MUxfwk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=UqyO7t/1fy+mL2H7PTPMM/UNE+XTtikoc/ToWLrxDZekalb9lHcnBbtCDl37G8Ak/ ji+9AQN+1qT5vP+rZVZHwl0baF+HY69SWKY2IIQZ+/Afo6kOa5pqHAhTcWOaKidF4D w5zs6x1lRtR3mRvonB2af5hoVV6Ah9H0lfLtsRJ0DNib5NgiCFh4Dz83UhE8j4y+7J uw3zqR1+2YRBiVTxTW4dz9qo4VEd4qemKVJXTFdL9/ASCGC6t49+VFgsio0ln7ZE9b F/fQchRrwr4mahx9TUtQvqPy+Q/MalSUVXDEy3ULklJIWizObX5f9JZosxkh/fZ8EV jOBfoA17AIlaQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WfTCv1CWNz4x3J; Thu, 8 Aug 2024 10:57:31 +1000 (AEST) Date: Thu, 8 Aug 2024 10:57:24 +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> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="1eVfT+Zdm1LrYuw9" Content-Disposition: inline In-Reply-To: <20240807112840.2113074-1-sbrivio@redhat.com> Message-ID-Hash: OOLZ3FVNLLU23TDMP25DES7UXSVDQV4L X-Message-ID-Hash: OOLZ3FVNLLU23TDMP25DES7UXSVDQV4L 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: --1eVfT+Zdm1LrYuw9 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 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). But, that's not a particularly strong opinion, so whatever. 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. Quoting getopt_long(3) | By default, getopt() permutes the contents of argv as it scans, so | that eventually all the nonoptions are at the end. Two other | scanning modes are also implemented. If the first character of | optstring is '+' or the environment variable POSIXLY_CORRECT is set, | then option processing stops as soon as a nonoption argument is | encountered. If '+' is not the first character of opt=E2=80=90 string, it | is treated as a normal option. If POSIXLY_CORRECT behaviour is | required in this case optstring will contain two '+' symbols. If | the first character of optstring is '-', then each nonoption | argv-element is handled as if it were the argument of an option with | character code 1. (This is used by programs that were written to | expect options and other argv-elements in any order and that care | about the ordering of the two.) The special argument "--" forces an | end of option-scanning regardless of the scanning mode. --=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 --1eVfT+Zdm1LrYuw9 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAma0F+YACgkQzQJF27ox 2GfCuA//Vhc7gQFb7vA6oMBe7oYjcvwpxK/SEqQtSobHU2ITIT3w888+3WAVdSBe mdban61AGIAeMObm5WXoQeWuhHlAn+dqA8qy6lfbCWKcJiYXz7lK1KfpPxJzGXrY qQknUYE2tvO1d+g0erAqrJcHsjy0DkoBTat/ZhwNAbLIfulN2vUX+DI2OHdpqQO1 27BQTbbY/o6tuRCe8nQHKVJTkQKwbAE/8MrcLPQlNvj59yCrZ/F8RJPQA/lH263t NmhUROxWGpP/8Esz2c9XQq0JzyfEDZeGCqUjfxkBAp6ZqP8/dTuuosZilEXN9W6Q S90Rmd2D3jR/a5yO3ayQjTTjLoYqvG3wUrr+H/yqpdT0musLDE8v4mVoKwiE0UIY 3W+pTcZB+bwNrzxfjupfc27w1NCQQ+f9werVSAZwc7F1AlJ5urOJvKoUMQ2DwcA9 rDNVKekCw438IUeORonTWJBSXs/v2irXEQt4RrGOuBlI0s06wHn2deEDtkxMspsL 3oa2bJeWVHHm5IB+fkQvK6yrMcLt6g4zKPeKtbCbyBH3JQgaHcDU8iTG9XNrhnZC W0Et2mFAQWkviDdWypxKpc8Vh+alHrc1Gu0fc44hcM0Mj4wYDdOCyzkxCThb224i +O8u1YPczTLt5iiL3Q+ac8TrIf8w+I8hbi90yJ1pdRQIgnUrBpY= =yz6u -----END PGP SIGNATURE----- --1eVfT+Zdm1LrYuw9--