2 This file is part of systemd.
4 Copyright 2014 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
27 #include "string-util.h"
31 int dispatch_verb(int argc, char *argv[], const Verb verbs[], void *userdata) {
38 assert(verbs[0].dispatch);
41 assert(argc >= optind);
49 /* At the end of the list? */
50 if (!verbs[i].dispatch) {
52 log_error("Unknown operation %s.", name);
54 log_error("Requires operation parameter.");
59 found = streq(name, verbs[i].verb);
61 found = !!(verbs[i].flags & VERB_DEFAULT);
74 if (verb->min_args != VERB_ANY &&
75 (unsigned) left < verb->min_args) {
76 log_error("Too few arguments.");
80 if (verb->max_args != VERB_ANY &&
81 (unsigned) left > verb->max_args) {
82 log_error("Too many arguments.");
86 if ((verb->flags & VERB_NOCHROOT) && running_in_chroot() > 0) {
87 log_info("Running in chroot, ignoring request.");
92 return verb->dispatch(left, argv + optind, userdata);
99 return verb->dispatch(1, fake, userdata);