public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
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 14:43:51 +1000	[thread overview]
Message-ID: <ZrRNBwJechUC-QO6@zatzit.fritz.box> (raw)
In-Reply-To: <20240808060228.03a33799@elisabeth>

[-- Attachment #1: Type: text/plain, Size: 2491 bytes --]

On Thu, Aug 08, 2024 at 06:02:28AM +0200, Stefano Brivio wrote:
> On Thu, 8 Aug 2024 10:57:24 +1000
> David Gibson <david@gibson.dropbear.id.au> wrote:
> 
> > 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).
> 
> 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.
> > 
> > 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.
> 
> 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.

-- 
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 --]

      reply	other threads:[~2024-08-08  4:44 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
2024-08-08  4:02   ` Stefano Brivio
2024-08-08  4:43     ` David Gibson [this message]

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=ZrRNBwJechUC-QO6@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).