summaryrefslogtreecommitdiff
path: root/main/cli.c
diff options
context:
space:
mode:
authorCorey Farrell <git@cfware.com>2017-12-29 19:24:02 -0500
committerCorey Farrell <git@cfware.com>2018-01-03 17:23:36 -0500
commit55f1d69c43d2c6c87eec50fd3eed7a77ba2e912b (patch)
tree0749060ca9d29dc796152f1654a340f091f4f600 /main/cli.c
parent7f4facc5e4a96ccae10283da998044becc4fbe11 (diff)
loader: Create ast_module_running_ref.
This function returns NULL if the module in question is not running. I did not change ast_module_ref as most callers do not check the result and they always call ast_module_unref. Make use of this function when running registered items from: * app_stack API's * bridge technologies * CLI commands * File formats * Manager Actions * RTP engines * Sorcery Wizards * Timing Interfaces * Translators * AGI Commands * Fax Technologies ASTERISK-20346 #close Change-Id: Ia16fd28e188b2fc0b9d18b8a5d9cacc31df73fcc
Diffstat (limited to 'main/cli.c')
-rw-r--r--main/cli.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/main/cli.c b/main/cli.c
index 1299c2aa7..80c184328 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -2679,9 +2679,12 @@ static char *__ast_cli_generator(const char *text, const char *word, int state,
.n = state - matchnum,
.argv = argv,
.argc = x};
- ast_module_ref(e->module);
- ret = e->handler(e, CLI_GENERATE, &a);
- ast_module_unref(e->module);
+
+ /* If the command is in a module it must be running. */
+ if (!e->module || ast_module_running_ref(e->module)) {
+ ret = e->handler(e, CLI_GENERATE, &a);
+ ast_module_unref(e->module);
+ }
}
if (ret)
break;
@@ -2760,9 +2763,11 @@ int ast_cli_command_full(int uid, int gid, int fd, const char *s)
*/
args[0] = (char *)e;
- ast_module_ref(e->module);
- retval = e->handler(e, CLI_HANDLER, &a);
- ast_module_unref(e->module);
+ /* If the command is in a module it must be running. */
+ if (!e->module || ast_module_running_ref(e->module)) {
+ retval = e->handler(e, CLI_HANDLER, &a);
+ ast_module_unref(e->module);
+ }
if (retval == CLI_SHOWUSAGE) {
ast_cli(fd, "%s", S_OR(e->usage, "Invalid usage, but no usage information available.\n"));