diff --git a/src/test/test-options.c b/src/test/test-options.c index 21fb7a2d028..1e4a02ea036 100644 --- a/src/test/test-options.c +++ b/src/test/test-options.c @@ -196,6 +196,20 @@ TEST(option_parse) { OPTION_PARSER_STOP_AT_FIRST_NONOPTION, NULL); + test_option_parse_one(STRV_MAKE("arg0", + "string1", + "--help", + "string2"), + options, + (Entry[]) { + { "help" }, + {} + }, + STRV_MAKE("string1", + "string2"), + OPTION_PARSER_NORMAL, + NULL); + test_option_parse_one(STRV_MAKE("arg0", "-h"), options, diff --git a/src/vmspawn/vmspawn.c b/src/vmspawn/vmspawn.c index 9d90cbed924..f3501c3b665 100644 --- a/src/vmspawn/vmspawn.c +++ b/src/vmspawn/vmspawn.c @@ -344,7 +344,11 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 0); assert(argv); - OptionParser opts = { argc, argv, OPTION_PARSER_STOP_AT_FIRST_NONOPTION }; + /* Our positional arguments are kernel command line arguments rather than a command to + * execute, and those never begin with a dash, so there's no reason to stop looking for + * options at the first of them. "--" still ends option parsing, for the rare argument that + * does look like an option. */ + OptionParser opts = { argc, argv }; FOREACH_OPTION_OR_RETURN(c, &opts) switch (c) {