]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run: use a "named namespace" also for the main option parser
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Tue, 28 Apr 2026 06:11:40 +0000 (08:11 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Tue, 28 Apr 2026 15:13:24 +0000 (17:13 +0200)
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.)

src/run/run.c
src/shared/options.h

index 885ad23b15f9c1ac681c2afb266c7feecd5b4ad1..ce35b48fba4cb06af8420c32133bcb9961e3b52e 100644 (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();
 
index 7d8507d0e54449321070f08377ea51655ba305af..8b8fc9ed4a81951b230c1e12143882562ad78267 100644 (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 {