From: Zbigniew Jędrzejewski-Szmek Date: Tue, 28 Apr 2026 06:11:40 +0000 (+0200) Subject: run: use a "named namespace" also for the main option parser X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a85be9ccf1bdd0fb19caf1178958f243c6fc9ee;p=thirdparty%2Fsystemd.git 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.) --- diff --git a/src/run/run.c b/src/run/run.c index 885ad23b15f..ce35b48fba4 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -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(); diff --git a/src/shared/options.h b/src/shared/options.h index 7d8507d0e54..8b8fc9ed4a8 100644 --- a/src/shared/options.h +++ b/src/shared/options.h @@ -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 {