diff options
author | Tilghman Lesher <tilghman@meg.abyt.es> | 2008-03-26 18:39:06 +0000 |
---|---|---|
committer | Tilghman Lesher <tilghman@meg.abyt.es> | 2008-03-26 18:39:06 +0000 |
commit | ef4eff9a9bcce416c25c089c4f86fd0b78d79028 (patch) | |
tree | e3b98ea87c1f245716b009b4b7173c660297f04e /main/config.c | |
parent | caf7b47b69d29e669aca53634bbcfbf74d23de1d (diff) |
Add the "config reload <conffile>" command, which allows you to tell Asterisk
to reload any file that references a given configuration file.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@111012 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/config.c')
-rw-r--r-- | main/config.c | 106 |
1 files changed, 105 insertions, 1 deletions
diff --git a/main/config.c b/main/config.c index 0c09cc8eb..29e2e123e 100644 --- a/main/config.c +++ b/main/config.c @@ -1827,7 +1827,7 @@ int read_config_maps(void) configtmp = ast_config_new(); configtmp->max_include_level = 1; - config = ast_config_internal_load(extconfig_conf, configtmp, flags, "", "config.c"); + config = ast_config_internal_load(extconfig_conf, configtmp, flags, "", "extconfig"); if (!config) { ast_config_destroy(configtmp); return 0; @@ -2345,8 +2345,112 @@ static char *handle_cli_core_show_config_mappings(struct ast_cli_entry *e, int c return CLI_SUCCESS; } +static char *handle_cli_config_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +{ + struct cache_file_mtime *cfmtime; + struct seenlist { + AST_LIST_ENTRY(seenlist) list; + char filename[0]; + } *seenlist; + AST_LIST_HEAD_NOLOCK(, seenlist) seenhead = AST_LIST_HEAD_NOLOCK_INIT_VALUE; + char *completion_value = NULL; + int wordlen, which = 0; + + switch (cmd) { + case CLI_INIT: + e->command = "config reload"; + e->usage = + "Usage: config reload <filename.conf>\n" + " Reloads all modules that reference <filename.conf>\n"; + return NULL; + case CLI_GENERATE: + if (a->pos > 2) { + return NULL; + } + + wordlen = strlen(a->word); + + AST_LIST_LOCK(&cfmtime_head); + AST_LIST_TRAVERSE(&cfmtime_head, cfmtime, list) { + int seen = 0; + AST_LIST_TRAVERSE(&seenhead, seenlist, list) { + if (strcmp(seenlist->filename, cfmtime->filename) == 0) { + seen = 1; + break; + } + } + + if (seen) { + continue; + } + + if (++which > a->n && strncmp(cfmtime->filename, a->word, wordlen) == 0) { + completion_value = ast_strdup(cfmtime->filename); + break; + } + + /* Otherwise save that we've seen this filename */ + if (!(seenlist = ast_malloc(sizeof(*seenlist) + strlen(cfmtime->filename) + 1))) { + break; + } + strcpy(seenlist->filename, cfmtime->filename); + AST_LIST_INSERT_HEAD(&seenhead, seenlist, list); + } + AST_LIST_UNLOCK(&cfmtime_head); + + /* Remove seenlist */ + while ((seenlist = AST_LIST_REMOVE_HEAD(&seenhead, list))) { + ast_free(seenlist); + } + + return completion_value; + } + + if (a->argc != 3) { + return CLI_SHOWUSAGE; + } + + AST_LIST_LOCK(&cfmtime_head); + AST_LIST_TRAVERSE(&cfmtime_head, cfmtime, list) { + if (!strcmp(cfmtime->filename, a->argv[2])) { + char *buf = alloca(strlen("module reload ") + strlen(cfmtime->who_asked) + 1); + sprintf(buf, "module reload %s", cfmtime->who_asked); + ast_cli_command(a->fd, buf); + } + } + AST_LIST_UNLOCK(&cfmtime_head); + + return CLI_SUCCESS; +} + +static char *handle_cli_config_list(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +{ + struct cache_file_mtime *cfmtime; + + switch (cmd) { + case CLI_INIT: + e->command = "config list"; + e->usage = + "Usage: config list\n" + " Show all modules that have loaded a configuration file\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + + AST_LIST_LOCK(&cfmtime_head); + AST_LIST_TRAVERSE(&cfmtime_head, cfmtime, list) { + ast_cli(a->fd, "%-20.20s %-50s\n", cfmtime->who_asked, cfmtime->filename); + } + AST_LIST_UNLOCK(&cfmtime_head); + + return CLI_SUCCESS; +} + static struct ast_cli_entry cli_config[] = { AST_CLI_DEFINE(handle_cli_core_show_config_mappings, "Display config mappings (file names to config engines)"), + AST_CLI_DEFINE(handle_cli_config_reload, "Force a reload on modules using a particular configuration file"), + AST_CLI_DEFINE(handle_cli_config_list, "Show all files that have loaded a configuration file"), }; int register_config_cli() |