From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top, Paul Holzinger <pholzing@redhat.com>
Subject: Re: [PATCH v2] conf: Stop parsing options at first non-option argument
Date: Thu, 8 Aug 2024 10:57:24 +1000 [thread overview]
Message-ID: <ZrQX9JwcpmyKWdhL@zatzit.fritz.box> (raw)
In-Reply-To: <20240807112840.2113074-1-sbrivio@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2687 bytes --]
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.
>
> Paul reports, for instance, that with:
>
> pasta --config-net ip -6 route
>
> -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.
>
> 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.
>
> Reported-by: Paul Holzinger <pholzing@redhat.com>
> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
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‐ 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.
--
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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2024-08-08 0:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-07 11:28 [PATCH v2] conf: Stop parsing options at first non-option argument Stefano Brivio
2024-08-08 0:57 ` David Gibson [this message]
2024-08-08 4:02 ` Stefano Brivio
2024-08-08 4:43 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZrQX9JwcpmyKWdhL@zatzit.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=pholzing@redhat.com \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).