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
This commit is contained in:
Tilghman Lesher
2008-03-26 18:39:06 +00:00
parent caf7b47b69
commit ef4eff9a9b
16 changed files with 131 additions and 24 deletions

View File

@@ -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()