mirror of
https://github.com/systemd/systemd.git
synced 2024-11-02 02:21:44 +03:00
verbs: when invoking the default verb, pass a faked argv array, with just the verb in it
That way the dispatcher calls know how they got called.
This commit is contained in:
parent
cd61c3bfd7
commit
43343ee7c2
@ -49,11 +49,10 @@ int dispatch_verb(int argc, char *argv[], const Verb verbs[], void *userdata) {
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (name)
|
||||||
if (!name)
|
|
||||||
found = !!(verbs[i].flags & VERB_DEFAULT);
|
|
||||||
else
|
|
||||||
found = streq(name, verbs[i].verb);
|
found = streq(name, verbs[i].verb);
|
||||||
|
else
|
||||||
|
found = !!(verbs[i].flags & VERB_DEFAULT);
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
verb = &verbs[i];
|
verb = &verbs[i];
|
||||||
@ -61,6 +60,11 @@ int dispatch_verb(int argc, char *argv[], const Verb verbs[], void *userdata) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(verb);
|
||||||
|
|
||||||
|
if (!name)
|
||||||
|
left = 1;
|
||||||
|
|
||||||
if (verb->min_args != VERB_ANY &&
|
if (verb->min_args != VERB_ANY &&
|
||||||
(unsigned) left < verb->min_args) {
|
(unsigned) left < verb->min_args) {
|
||||||
log_error("Too few arguments.");
|
log_error("Too few arguments.");
|
||||||
@ -73,5 +77,14 @@ int dispatch_verb(int argc, char *argv[], const Verb verbs[], void *userdata) {
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (name)
|
||||||
return verb->dispatch(left, argv + optind, userdata);
|
return verb->dispatch(left, argv + optind, userdata);
|
||||||
|
else {
|
||||||
|
char* fake[2] = {
|
||||||
|
(char*) verb->verb,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
return verb->dispatch(1, fake, userdata);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user