run: use a "named namespace" also for the main option parser

It seems that clang reorders the entries in the options array that
originate from different functions, but not within a function. Using
"named namespaces" exclusively should sidestep the issue.

(A bigger hammer would be to sort the array. We *can* do this, since the
options have the increasing .id field. But that'd require duplicating
the memory or making it writable. Let's avoid this until we know for
sure that it's needed.)
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-04-28 17:13:24 +02:00
parent 03a58fe251
commit 0a85be9ccf
2 changed files with 6 additions and 2 deletions
+4 -2
View File
@@ -154,7 +154,7 @@ static int help(void) {
_cleanup_(table_unref_many) Table *tables[ELEMENTSOF(groups) + 1] = {};
for (size_t i = 0; i < ELEMENTSOF(groups); i++) {
r = option_parser_get_help_table_group(groups[i], &tables[i]);
r = option_parser_get_help_table_full("systemd-run", groups[i], &tables[i]);
if (r < 0)
return r;
}
@@ -252,11 +252,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
OptionParser opts = { argc, argv, OPTION_PARSER_STOP_AT_FIRST_NONOPTION };
OptionParser opts = { argc, argv, OPTION_PARSER_STOP_AT_FIRST_NONOPTION, "systemd-run" };
FOREACH_OPTION(c, &opts, /* on_error= */ return c)
switch (c) {
OPTION_NAMESPACE("systemd-run"): {}
OPTION_COMMON_HELP:
return help();
+2
View File
@@ -9,6 +9,8 @@
* By default, options defined in a single program are all placed in a single (unnamed) namespace
* and in a single (unnamed) group. OPTION_NAMESPACE() marks the beginning of a named namespace.
* OPTION_GROUP() marks the beginning of a named group.
*
* Note: if multiple namespaces are used, they should all be named.
*/
typedef enum OptionFlags {