summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-12-19 19:17:52 +0100
committerLennart Poettering <lennart@poettering.net>2014-12-19 19:19:29 +0100
commit43343ee7c298dad8db0698b4c181a42ecb7bb216 (patch)
tree2445456a01f775472cc95ec11b453402c748c36c
parentcd61c3bfd718fb398cc53ced906266a9297782c9 (diff)
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.
-rw-r--r--src/shared/verbs.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/shared/verbs.c b/src/shared/verbs.c
index ead2ff60f4..bc1ae43535 100644
--- a/src/shared/verbs.c
+++ b/src/shared/verbs.c
@@ -49,11 +49,10 @@ int dispatch_verb(int argc, char *argv[], const Verb verbs[], void *userdata) {
return -EINVAL;
}
-
- if (!name)
- found = !!(verbs[i].flags & VERB_DEFAULT);
- else
+ if (name)
found = streq(name, verbs[i].verb);
+ else
+ found = !!(verbs[i].flags & VERB_DEFAULT);
if (found) {
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 &&
(unsigned) left < verb->min_args) {
log_error("Too few arguments.");
@@ -73,5 +77,14 @@ int dispatch_verb(int argc, char *argv[], const Verb verbs[], void *userdata) {
return -EINVAL;
}
- return verb->dispatch(left, argv + optind, userdata);
+ if (name)
+ return verb->dispatch(left, argv + optind, userdata);
+ else {
+ char* fake[2] = {
+ (char*) verb->verb,
+ NULL
+ };
+
+ return verb->dispatch(1, fake, userdata);
+ }
}