2 * Asterisk -- A telephony toolkit for Linux.
4 * Standard Command Line Interface
6 * Copyright (C) 1999, Mark Spencer
8 * Mark Spencer <markster@linux-support.net>
10 * This program is free software, distributed under the terms of
11 * the GNU General Public License
16 #include <asterisk/logger.h>
17 #include <asterisk/options.h>
18 #include <asterisk/cli.h>
19 #include <asterisk/module.h>
20 #include <asterisk/channel.h>
21 #include <asterisk/channel_pvt.h>
22 #include <asterisk/utils.h>
23 #include <sys/signal.h>
28 /* For rl_filename_completion */
29 #include "editline/readline/readline.h"
30 /* For module directory */
35 #define VERSION_INFO "Asterisk " ASTERISK_VERSION " built by " BUILD_USER "@" BUILD_HOSTNAME \
36 " on a " BUILD_MACHINE " running " BUILD_OS
38 void ast_cli(int fd, char *fmt, ...)
43 vasprintf(&stuff, fmt, ap);
45 write(fd, stuff, strlen(stuff));
49 ast_mutex_t clilock = AST_MUTEX_INITIALIZER;
52 struct ast_cli_entry *helpers = NULL;
54 static char load_help[] =
55 "Usage: load <module name>\n"
56 " Loads the specified module into Asterisk.\n";
58 static char unload_help[] =
59 "Usage: unload [-f|-h] <module name>\n"
60 " Unloads the specified module from Asterisk. The -f\n"
61 " option causes the module to be unloaded even if it is\n"
62 " in use (may cause a crash) and the -h module causes the\n"
63 " module to be unloaded even if the module says it cannot, \n"
64 " which almost always will cause a crash.\n";
66 static char help_help[] =
67 "Usage: help [topic]\n"
68 " When called with a topic as an argument, displays usage\n"
69 " information on the given command. If called without a\n"
70 " topic, it provides a list of commands.\n";
72 static char chanlist_help[] =
73 "Usage: show channels\n"
74 " Lists currently defined channels and some information about\n"
77 static char reload_help[] =
79 " Reloads configuration files for all modules which support\n"
82 static char set_verbose_help[] =
83 "Usage: set verbose <level>\n"
84 " Sets level of verbose messages to be displayed. 0 means\n"
85 " no messages should be displayed.\n";
87 static char softhangup_help[] =
88 "Usage: soft hangup <channel>\n"
89 " Request that a channel be hung up. The hangup takes effect\n"
90 " the next time the driver reads or writes from the channel\n";
92 static int handle_load(int fd, int argc, char *argv[])
95 return RESULT_SHOWUSAGE;
96 if (ast_load_resource(argv[1])) {
97 ast_cli(fd, "Unable to load module %s\n", argv[1]);
98 return RESULT_FAILURE;
100 return RESULT_SUCCESS;
103 static int handle_reload(int fd, int argc, char *argv[])
106 return RESULT_SHOWUSAGE;
108 return RESULT_SUCCESS;
111 static int handle_set_verbose(int fd, int argc, char *argv[])
114 /* Has a hidden 'at least' argument */
115 if ((argc != 3) && (argc != 4))
116 return RESULT_SHOWUSAGE;
117 if ((argc == 4) && strcasecmp(argv[2], "atleast"))
118 return RESULT_SHOWUSAGE;
120 option_verbose = atoi(argv[2]);
123 if (val > option_verbose)
124 option_verbose = val;
126 return RESULT_SUCCESS;
129 static int handle_unload(int fd, int argc, char *argv[])
132 int force=AST_FORCE_SOFT;
134 return RESULT_SHOWUSAGE;
135 for (x=1;x<argc;x++) {
136 if (argv[x][0] == '-') {
139 force = AST_FORCE_FIRM;
142 force = AST_FORCE_HARD;
145 return RESULT_SHOWUSAGE;
147 } else if (x != argc - 1)
148 return RESULT_SHOWUSAGE;
149 else if (ast_unload_resource(argv[x], force)) {
150 ast_cli(fd, "Unable to unload resource %s\n", argv[x]);
151 return RESULT_FAILURE;
154 return RESULT_SUCCESS;
157 #define MODLIST_FORMAT "%-25s %-40.40s %-10d\n"
158 #define MODLIST_FORMAT2 "%-25s %-40.40s %-10s\n"
160 static ast_mutex_t climodentrylock = AST_MUTEX_INITIALIZER;
161 static int climodentryfd = -1;
163 static int modlist_modentry(char *module, char *description, int usecnt)
165 ast_cli(climodentryfd, MODLIST_FORMAT, module, description, usecnt);
169 static char modlist_help[] =
170 "Usage: show modules\n"
171 " Shows Asterisk modules currently in use, and usage "
174 static char version_help[] =
175 "Usage: show version\n"
176 " Shows Asterisk version information.\n ";
178 static char *format_uptimestr(time_t timeval)
180 int years = 0, weeks = 0, days = 0, hours = 0, mins = 0, secs = 0;
184 #define MIN (SECOND*60)
185 #define HOUR (MIN*60)
186 #define DAY (HOUR*24)
188 #define YEAR (DAY*365)
192 if (timeval > YEAR) {
193 years = (timeval / YEAR);
194 timeval -= (years * YEAR);
196 pos += sprintf(timestr + pos, "%d years, ", years);
198 pos += sprintf(timestr + pos, "1 year, ");
200 if (timeval > WEEK) {
201 weeks = (timeval / WEEK);
202 timeval -= (weeks * WEEK);
204 pos += sprintf(timestr + pos, "%d weeks, ", weeks);
206 pos += sprintf(timestr + pos, "1 week, ");
209 days = (timeval / DAY);
210 timeval -= (days * DAY);
212 pos += sprintf(timestr + pos, "%d days, ", days);
214 pos += sprintf(timestr + pos, "1 day, ");
217 if (timeval > HOUR) {
218 hours = (timeval / HOUR);
219 timeval -= (hours * HOUR);
221 pos += sprintf(timestr + pos, "%d hours, ", hours);
223 pos += sprintf(timestr + pos, "1 hour, ");
226 mins = (timeval / MIN);
227 timeval -= (mins * MIN);
229 pos += sprintf(timestr + pos, "%d minutes, ", mins);
231 pos += sprintf(timestr + pos, "1 minute, ");
236 pos += sprintf(timestr + pos, "%d seconds", secs);
238 return timestr ? strdup(timestr) : NULL;
241 static int handle_showuptime(int fd, int argc, char *argv[])
243 time_t curtime, tmptime;
247 if (ast_startuptime) {
248 tmptime = curtime - ast_startuptime;
249 timestr = format_uptimestr(tmptime);
251 ast_cli(fd, "System uptime: %s\n", timestr);
255 if (ast_lastreloadtime) {
256 tmptime = curtime - ast_lastreloadtime;
257 timestr = format_uptimestr(tmptime);
259 ast_cli(fd, "Last reload: %s\n", timestr);
263 return RESULT_SUCCESS;
266 static int handle_modlist(int fd, int argc, char *argv[])
269 return RESULT_SHOWUSAGE;
270 ast_mutex_lock(&climodentrylock);
272 ast_cli(fd, MODLIST_FORMAT2, "Module", "Description", "Use Count");
273 ast_update_module_list(modlist_modentry);
275 ast_mutex_unlock(&climodentrylock);
276 return RESULT_SUCCESS;
279 static int handle_version(int fd, int argc, char *argv[])
282 return RESULT_SHOWUSAGE;
283 ast_cli(fd, "%s\n", VERSION_INFO);
284 return RESULT_SUCCESS;
286 static int handle_chanlist(int fd, int argc, char *argv[])
288 #define FORMAT_STRING "%15s (%-10s %-12s %-4d) %7s %-12s %-15s\n"
289 #define FORMAT_STRING2 "%15s (%-10s %-12s %-4s) %7s %-12s %-15s\n"
290 struct ast_channel *c=NULL;
293 return RESULT_SHOWUSAGE;
294 c = ast_channel_walk(NULL);
295 ast_cli(fd, FORMAT_STRING2, "Channel", "Context", "Extension", "Pri", "State", "Appl.", "Data");
297 ast_cli(fd, FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
298 c->appl ? c->appl : "(None)", c->data ? ( !ast_strlen_zero(c->data) ? c->data : "(Empty)" ): "(None)");
300 c = ast_channel_walk(c);
302 ast_cli(fd, "%d active channel(s)\n", numchans);
303 return RESULT_SUCCESS;
306 static char showchan_help[] =
307 "Usage: show channel <channel>\n"
308 " Shows lots of information about the specified channel.\n";
310 static char debugchan_help[] =
311 "Usage: debug channel <channel>\n"
312 " Enables debugging on a specific channel.\n";
314 static char nodebugchan_help[] =
315 "Usage: no debug channel <channel>\n"
316 " Disables debugging on a specific channel.\n";
318 static char commandcomplete_help[] =
319 "Usage: _command complete \"<line>\" text state\n"
320 " This function is used internally to help with command completion and should.\n"
321 " never be called by the user directly.\n";
323 static char commandnummatches_help[] =
324 "Usage: _command nummatches \"<line>\" text \n"
325 " This function is used internally to help with command completion and should.\n"
326 " never be called by the user directly.\n";
328 static char commandmatchesarray_help[] =
329 "Usage: _command matchesarray \"<line>\" text \n"
330 " This function is used internally to help with command completion and should.\n"
331 " never be called by the user directly.\n";
333 static int handle_softhangup(int fd, int argc, char *argv[])
335 struct ast_channel *c=NULL;
337 return RESULT_SHOWUSAGE;
338 c = ast_channel_walk(NULL);
340 if (!strcasecmp(c->name, argv[2])) {
341 ast_cli(fd, "Requested Hangup on channel '%s'\n", c->name);
342 ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
345 c = ast_channel_walk(c);
348 ast_cli(fd, "%s is not a known channel\n", argv[2]);
349 return RESULT_SUCCESS;
352 static char *__ast_cli_generator(char *text, char *word, int state, int lock);
354 static int handle_commandmatchesarray(int fd, int argc, char *argv[])
363 return RESULT_SHOWUSAGE;
364 buf = malloc(buflen);
366 return RESULT_FAILURE;
368 matches = ast_cli_completion_matches(argv[2], argv[3]);
370 for (x=0; matches[x]; x++) {
372 printf("command matchesarray for '%s' %s got '%s'\n", argv[2], argv[3], matches[x]);
374 if (len + strlen(matches[x]) >= buflen) {
375 buflen += strlen(matches[x]) * 3;
376 buf = realloc(buf, buflen);
378 len += sprintf( buf + len, "%s ", matches[x]);
385 printf("array for '%s' %s got '%s'\n", argv[2], argv[3], buf);
389 ast_cli(fd, "%s%s",buf, AST_CLI_COMPLETE_EOF);
392 ast_cli(fd, "NULL\n");
394 return RESULT_SUCCESS;
399 static int handle_commandnummatches(int fd, int argc, char *argv[])
404 return RESULT_SHOWUSAGE;
406 matches = ast_cli_generatornummatches(argv[2], argv[3]);
409 printf("Search for '%s' %s got '%d'\n", argv[2], argv[3], matches);
411 ast_cli(fd, "%d", matches);
413 return RESULT_SUCCESS;
416 static int handle_commandcomplete(int fd, int argc, char *argv[])
420 printf("Search for %d args: '%s', '%s', '%s', '%s'\n", argc, argv[0], argv[1], argv[2], argv[3]);
423 return RESULT_SHOWUSAGE;
424 buf = __ast_cli_generator(argv[2], argv[3], atoi(argv[4]), 0);
426 printf("Search for '%s' %s %d got '%s'\n", argv[2], argv[3], atoi(argv[4]), buf);
432 ast_cli(fd, "NULL\n");
433 return RESULT_SUCCESS;
436 static int handle_debugchan(int fd, int argc, char *argv[])
438 struct ast_channel *c=NULL;
440 return RESULT_SHOWUSAGE;
441 c = ast_channel_walk(NULL);
443 if (!strcasecmp(c->name, argv[2])) {
444 c->fin |= 0x80000000;
445 c->fout |= 0x80000000;
448 c = ast_channel_walk(c);
451 ast_cli(fd, "Debugging enabled on channel %s\n", c->name);
453 ast_cli(fd, "No such channel %s\n", argv[2]);
454 return RESULT_SUCCESS;
457 static int handle_nodebugchan(int fd, int argc, char *argv[])
459 struct ast_channel *c=NULL;
461 return RESULT_SHOWUSAGE;
462 c = ast_channel_walk(NULL);
464 if (!strcasecmp(c->name, argv[3])) {
465 c->fin &= 0x7fffffff;
466 c->fout &= 0x7fffffff;
469 c = ast_channel_walk(c);
472 ast_cli(fd, "Debugging disabled on channel %s\n", c->name);
474 ast_cli(fd, "No such channel %s\n", argv[2]);
475 return RESULT_SUCCESS;
480 static int handle_showchan(int fd, int argc, char *argv[])
482 struct ast_channel *c=NULL;
484 return RESULT_SHOWUSAGE;
485 c = ast_channel_walk(NULL);
487 if (!strcasecmp(c->name, argv[2])) {
497 " NativeFormat: %d\n"
500 "1st File Descriptor: %d\n"
502 " Frames out: %d%s\n"
503 " Time to Hangup: %ld\n"
509 " Pickup Group: %d\n"
513 " Blocking in: %s\n",
514 c->name, c->type, c->uniqueid,
515 (c->callerid ? c->callerid : "(N/A)"),
516 (c->dnid ? c->dnid : "(N/A)" ), ast_state2str(c->_state), c->_state, c->rings, c->nativeformats, c->writeformat, c->readformat,
517 c->fds[0], c->fin & 0x7fffffff, (c->fin & 0x80000000) ? " (DEBUGGED)" : "",
518 c->fout & 0x7fffffff, (c->fout & 0x80000000) ? " (DEBUGGED)" : "", (long)c->whentohangup,
519 c->context, c->exten, c->priority, c->callgroup, c->pickupgroup, ( c->appl ? c->appl : "(N/A)" ),
520 ( c-> data ? (!ast_strlen_zero(c->data) ? c->data : "(Empty)") : "(None)"),
521 c->stack, (c->blocking ? c->blockproc : "(Not Blocking)"));
525 c = ast_channel_walk(c);
528 ast_cli(fd, "%s is not a known channel\n", argv[2]);
529 return RESULT_SUCCESS;
532 static char *complete_ch(char *line, char *word, int pos, int state)
534 struct ast_channel *c;
536 c = ast_channel_walk(NULL);
538 if (!strncasecmp(word, c->name, strlen(word))) {
542 c = ast_channel_walk(c);
544 return c ? strdup(c->name) : NULL;
547 static char *complete_fn(char *line, char *word, int pos, int state)
554 strncpy(filename, word, sizeof(filename)-1);
556 snprintf(filename, sizeof(filename), "%s/%s", (char *)ast_config_AST_MODULE_DIR, word);
557 c = (char*)filename_completion_function(filename, state);
558 if (c && word[0] != '/')
559 c += (strlen((char*)ast_config_AST_MODULE_DIR) + 1);
560 return c ? strdup(c) : c;
563 static int handle_help(int fd, int argc, char *argv[]);
565 static struct ast_cli_entry builtins[] = {
566 /* Keep alphabetized, with longer matches first (example: abcd before abc) */
567 { { "_command", "complete", NULL }, handle_commandcomplete, "Command complete", commandcomplete_help },
568 { { "_command", "nummatches", NULL }, handle_commandnummatches, "Returns number of command matches", commandnummatches_help },
569 { { "_command", "matchesarray", NULL }, handle_commandmatchesarray, "Returns command matches array", commandmatchesarray_help },
570 { { "debug", "channel", NULL }, handle_debugchan, "Enable debugging on a channel", debugchan_help, complete_ch },
571 { { "help", NULL }, handle_help, "Display help list, or specific help on a command", help_help },
572 { { "load", NULL }, handle_load, "Load a dynamic module by name", load_help, complete_fn },
573 { { "no", "debug", "channel", NULL }, handle_nodebugchan, "Disable debugging on a channel", nodebugchan_help, complete_ch },
574 { { "reload", NULL }, handle_reload, "Reload configuration", reload_help },
575 { { "set", "verbose", NULL }, handle_set_verbose, "Set level of verboseness", set_verbose_help },
576 { { "show", "channels", NULL }, handle_chanlist, "Display information on channels", chanlist_help },
577 { { "show", "channel", NULL }, handle_showchan, "Display information on a specific channel", showchan_help, complete_ch },
578 { { "show", "modules", NULL }, handle_modlist, "List modules and info", modlist_help },
579 { { "show", "uptime", NULL }, handle_showuptime, "Show uptime information", modlist_help },
580 { { "show", "version", NULL }, handle_version, "Display version info", version_help },
581 { { "soft", "hangup", NULL }, handle_softhangup, "Request a hangup on a given channel", softhangup_help, complete_ch },
582 { { "unload", NULL }, handle_unload, "Unload a dynamic module by name", unload_help, complete_fn },
583 { { NULL }, NULL, NULL, NULL }
586 static struct ast_cli_entry *find_cli(char *cmds[], int exact)
591 struct ast_cli_entry *e=NULL;
592 for (x=0;builtins[x].cmda[0];x++) {
593 /* start optimistic */
595 for (y=0;match && cmds[y]; y++) {
596 /* If there are no more words in the candidate command, then we're
598 if (!builtins[x].cmda[y] && !exact)
600 /* If there are no more words in the command (and we're looking for
601 an exact match) or there is a difference between the two words,
602 then this is not a match */
603 if (!builtins[x].cmda[y] || strcasecmp(builtins[x].cmda[y], cmds[y]))
606 /* If more words are needed to complete the command then this is not
607 a candidate (unless we're looking for a really inexact answer */
608 if ((exact > -1) && builtins[x].cmda[y])
613 for (e=helpers;e;e=e->next) {
615 for (y=0;match && cmds[y]; y++) {
616 if (!e->cmda[y] && !exact)
618 if (!e->cmda[y] || strcasecmp(e->cmda[y], cmds[y]))
621 if ((exact > -1) && e->cmda[y])
629 static void join(char *s, int len, char *w[])
632 /* Join words into a string */
636 strncat(s, " ", len - strlen(s));
637 strncat(s, w[x], len - strlen(s));
641 static void join2(char *s, int len, char *w[])
644 /* Join words into a string */
647 strncat(s, w[x], len - strlen(s));
651 static char *find_best(char *argv[])
653 static char cmdline[80];
655 /* See how close we get, then print the */
656 char *myargv[AST_MAX_CMD_LEN];
657 for (x=0;x<AST_MAX_CMD_LEN;x++)
659 for (x=0;argv[x];x++) {
661 if (!find_cli(myargv, -1))
664 join(cmdline, sizeof(cmdline), myargv);
668 int ast_cli_unregister(struct ast_cli_entry *e)
670 struct ast_cli_entry *cur, *l=NULL;
671 ast_mutex_lock(&clilock);
676 ast_log(LOG_WARNING, "Can't remove command that is in use\n");
690 ast_mutex_unlock(&clilock);
694 int ast_cli_register(struct ast_cli_entry *e)
696 struct ast_cli_entry *cur, *l=NULL;
697 char fulle[80] ="", fulltst[80] ="";
699 ast_mutex_lock(&clilock);
700 join2(fulle, sizeof(fulle), e->cmda);
701 if (find_cli(e->cmda, -1)) {
702 ast_mutex_unlock(&clilock);
703 ast_log(LOG_WARNING, "Command '%s' already registered (or something close enough)\n", fulle);
708 join2(fulltst, sizeof(fulltst), cur->cmda);
709 len = strlen(fulltst);
710 if (strlen(fulle) < len)
712 if (strncasecmp(fulle, fulltst, len) < 0) {
732 ast_mutex_unlock(&clilock);
736 static int help_workhorse(int fd, char *match[])
742 struct ast_cli_entry *e, *e1, *e2;
746 join(matchstr, sizeof(matchstr), match);
747 while(e1->cmda[0] || e2) {
749 join(fullcmd2, sizeof(fullcmd2), e2->cmda);
751 join(fullcmd1, sizeof(fullcmd1), e1->cmda);
753 (e2 && (strcmp(fullcmd2, fullcmd1) < 0))) {
757 /* Increment by going to next */
765 /* Hide commands that start with '_' */
766 if (fullcmd[0] == '_')
769 if (strncasecmp(matchstr, fullcmd, strlen(matchstr))) {
773 ast_cli(fd, "%25.25s %s\n", fullcmd, e->summary);
778 static int handle_help(int fd, int argc, char *argv[]) {
779 struct ast_cli_entry *e;
782 return RESULT_SHOWUSAGE;
784 e = find_cli(argv + 1, 1);
786 ast_cli(fd, e->usage);
788 if (find_cli(argv + 1, -1)) {
789 return help_workhorse(fd, argv + 1);
791 join(fullcmd, sizeof(fullcmd), argv+1);
792 ast_cli(fd, "No such command '%s'.\n", fullcmd);
796 return help_workhorse(fd, NULL);
798 return RESULT_SUCCESS;
801 static char *parse_args(char *s, int *max, char *argv[])
815 /* If it's escaped, put a literal quote */
820 if (quoted && whitespace) {
821 /* If we're starting a quote, coming off white space start a new word, too */
829 if (!quoted && !escaped) {
830 /* If we're not quoted, mark this as whitespace, and
831 end the previous argument */
835 /* Otherwise, just treat it as anything else */
839 /* If we're escaped, print a literal, otherwise enable escaping */
849 if (x >= AST_MAX_ARGS -1) {
850 ast_log(LOG_WARNING, "Too many arguments, truncating\n");
853 /* Coming off of whitespace, start the next argument */
870 /* This returns the number of unique matches for the generator */
871 int ast_cli_generatornummatches(char *text, char *word)
873 int matches = 0, i = 0;
874 char *buf, *oldbuf = NULL;
877 while ( (buf = ast_cli_generator(text, word, i)) ) {
878 if (++i > 1 && strcmp(buf,oldbuf) == 0) {
888 char **ast_cli_completion_matches(char *text, char *word)
890 char **match_list = NULL, *retstr, *prevstr;
891 size_t match_list_len, max_equal, which, i;
895 while ((retstr = ast_cli_generator(text, word, matches)) != NULL) {
896 if (matches + 1 >= match_list_len) {
897 match_list_len <<= 1;
898 match_list = realloc(match_list, match_list_len * sizeof(char *));
900 match_list[++matches] = retstr;
904 return (char **) NULL;
907 prevstr = match_list[1];
908 max_equal = strlen(prevstr);
909 for (; which <= matches; which++) {
910 for (i = 0; i < max_equal && prevstr[i] == match_list[which][i]; i++)
915 retstr = malloc(max_equal + 1);
916 (void) strncpy(retstr, match_list[1], max_equal);
917 retstr[max_equal] = '\0';
918 match_list[0] = retstr;
920 if (matches + 1 >= match_list_len)
921 match_list = realloc(match_list, (match_list_len + 1) * sizeof(char *));
922 match_list[matches + 1] = (char *) NULL;
927 static char *__ast_cli_generator(char *text, char *word, int state, int lock)
929 char *argv[AST_MAX_ARGS];
930 struct ast_cli_entry *e, *e1, *e2;
939 if ((dup = parse_args(text, &x, argv))) {
940 join(matchstr, sizeof(matchstr), argv);
942 ast_mutex_lock(&clilock);
945 while(e1->cmda[0] || e2) {
947 join(fullcmd2, sizeof(fullcmd2), e2->cmda);
949 join(fullcmd1, sizeof(fullcmd1), e1->cmda);
951 (e2 && (strcmp(fullcmd2, fullcmd1) < 0))) {
955 /* Increment by going to next */
963 if ((fullcmd[0] != '_') && !strncasecmp(text, fullcmd, strlen(text))) {
964 /* We contain the first part of one or more commands */
966 if (matchnum > state) {
967 /* Now, what we're supposed to return is the next word... */
968 if (!ast_strlen_zero(word) && x>0) {
975 ast_mutex_unlock(&clilock);
977 return res ? strdup(res) : NULL;
981 if (e->generator && !strncasecmp(matchstr, fullcmd, strlen(fullcmd))) {
982 /* We have a command in its entirity within us -- theoretically only one
983 command can have this occur */
984 fullcmd = e->generator(text, word, (strlen(word) ? (x - 1) : (x)), state);
986 ast_mutex_unlock(&clilock);
993 ast_mutex_unlock(&clilock);
999 char *ast_cli_generator(char *text, char *word, int state)
1001 return __ast_cli_generator(text, word, state, 1);
1004 int ast_cli_command(int fd, char *s)
1006 char *argv[AST_MAX_ARGS];
1007 struct ast_cli_entry *e;
1011 if ((dup = parse_args(s, &x, argv))) {
1012 /* We need at least one entry, or ignore */
1014 ast_mutex_lock(&clilock);
1015 e = find_cli(argv, 0);
1018 ast_mutex_unlock(&clilock);
1020 switch(e->handler(fd, x, argv)) {
1021 case RESULT_SHOWUSAGE:
1022 ast_cli(fd, e->usage);
1026 ast_cli(fd, "No such command '%s' (type 'help' for help)\n", find_best(argv));
1028 ast_mutex_lock(&clilock);
1030 ast_mutex_unlock(&clilock);
1035 ast_log(LOG_WARNING, "Out of memory\n");