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(a)redhat.com> Signed-off-by: Stefano Brivio <sbrivio(a)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