The behaviour that was implemented in systemd-dissect was that
both '--exec -- cmd' and '--exec cmd' result in 'cmd' as the command,
and '--' anywhere later is as a positional argument, so nesting is
possible, e.g.:
--exec -- cmd --opt -- another-cmd --another-opt
This is not obvious, so add some tests for this and keep it as a separate
commit.
return 0;
}
- if (!state->parsing_stopped &&
- argv[state->optind][0] == '-' &&
+ if (state->parsing_stopped)
+ return 0;
+
+ if (argv[state->optind][0] == '-' &&
argv[state->optind][1] != '\0')
/* Looks like we found an option parameter */
break;
NULL);
/* OPTION_STOPS_PARSING then "--": "--" is still consumed after exec */
+ test_macros_parse_one(STRV_MAKE("arg0",
+ "--help",
+ "--exec",
+ "--",
+ "--version",
+ "-h"),
+ (Entry[]) {
+ { "help" },
+ { "exec" },
+ {}
+ },
+ STRV_MAKE("--version",
+ "-h"));
+
+ /* OPTION_STOPS_PARSING then later "--": "--" is not consumed */
test_macros_parse_one(STRV_MAKE("arg0",
"--help",
"--exec",
{}
},
STRV_MAKE("--version",
+ "--",
+ "-h"));
+
+ /* OPTION_STOPS_PARSING then "--" twice: second "--" is not consumed */
+ test_macros_parse_one(STRV_MAKE("arg0",
+ "--help",
+ "--exec",
+ "--",
+ "--",
+ "--version",
+ "-h"),
+ (Entry[]) {
+ { "help" },
+ { "exec" },
+ {}
+ },
+ STRV_MAKE("--",
+ "--version",
"-h"));
}