]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/verbs: allow all groups to be named
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Wed, 13 May 2026 05:47:40 +0000 (07:47 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Wed, 13 May 2026 07:00:41 +0000 (09:00 +0200)
When verb groups were added, I assumed that the first group will always
by the unnamed group, or in other words, that VERB_GROUP() line cannot
appear first. This provides an additional check on the whether the verbs
haven't been reordered by the compiler or linker. But that check is weak
and we can do a better check anyway. And this limitation is unexpected,
since we allow that for OPTIONs. The code should all work without an
unnamed group, once this assertion is removed.

src/shared/verbs.c

index 274945e5c5977563e28266664a25955690b0946c..e488af63fecd41a166da95867657fcf0ab6cde37 100644 (file)
@@ -83,7 +83,6 @@ int _dispatch_verb_with_args(char **args, const Verb verbs[], const Verb verbs_e
 
         assert(verbs);
         assert(verbs_end > verbs);
-        assert(verbs[0].dispatch);
         assert(verbs[0].verb);
 
         const char *name = args ? args[0] : NULL;
@@ -101,6 +100,7 @@ int _dispatch_verb_with_args(char **args, const Verb verbs[], const Verb verbs_e
                         if (r < 0)
                                 return log_oom();
                 }
+                assert(!strv_isempty(verb_strv));  /* At least one verb should be defined… */
 
                 if (name) {
                         /* Be more helpful to the user, and give a hint what the user might have wanted to type. */
@@ -121,7 +121,7 @@ int _dispatch_verb_with_args(char **args, const Verb verbs[], const Verb verbs_e
                                                "Command verb required (one of %s).", joined);
                 }
 
-                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Command verb '%s' required.", verbs[0].verb);
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Command verb '%s' required.", verb_strv[0]);
         }
 
         if (!name)