diff options
Diffstat (limited to 'main/config.c')
-rw-r--r-- | main/config.c | 58 |
1 files changed, 42 insertions, 16 deletions
diff --git a/main/config.c b/main/config.c index dfa6f0923..f7f0d7be1 100644 --- a/main/config.c +++ b/main/config.c @@ -30,6 +30,11 @@ <support_level>core</support_level> ***/ +/* This maintains the original "module reload extconfig" CLI command instead + * of replacing it with "module reload config". */ +#undef AST_MODULE +#define AST_MODULE "extconfig" + #include "asterisk.h" #include "asterisk/paths.h" /* use ast_config_AST_CONFIG_DIR */ @@ -54,6 +59,7 @@ #include "asterisk/astobj2.h" #include "asterisk/strings.h" /* for the ast_str_*() API */ #include "asterisk/netsock2.h" +#include "asterisk/module.h" #define MAX_NESTED_COMMENTS 128 #define COMMENT_START ";--" @@ -2496,11 +2502,6 @@ static void insert_leading_blank_lines(FILE *fp, struct inclfile *fi, struct ast fi->lineno = lineno + 1; /* Advance the file lineno */ } -int config_text_file_save(const char *configfile, const struct ast_config *cfg, const char *generator) -{ - return ast_config_text_file_save2(configfile, cfg, generator, CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT); -} - int ast_config_text_file_save(const char *configfile, const struct ast_config *cfg, const char *generator) { return ast_config_text_file_save2(configfile, cfg, generator, CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT); @@ -2875,7 +2876,7 @@ static int ast_realtime_append_mapping(const char *name, const char *driver, con return 0; } -int read_config_maps(void) +static int reload_module(void) { struct ast_config *config, *configtmp; struct ast_variable *v; @@ -3924,8 +3925,8 @@ static char *handle_cli_core_show_config_mappings(struct ast_cli_entry *e, int c static char *handle_cli_config_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct cache_file_mtime *cfmtime; - char *prev = "", *completion_value = NULL; - int wordlen, which = 0; + char *prev = ""; + int wordlen; switch (cmd) { case CLI_INIT: @@ -3943,19 +3944,20 @@ static char *handle_cli_config_reload(struct ast_cli_entry *e, int cmd, struct a AST_LIST_LOCK(&cfmtime_head); AST_LIST_TRAVERSE(&cfmtime_head, cfmtime, list) { - /* Skip duplicates - this only works because the list is sorted by filename */ - if (strcmp(cfmtime->filename, prev) == 0) { + /* Core configs cannot be reloaded */ + if (ast_strlen_zero(cfmtime->who_asked)) { continue; } - /* Core configs cannot be reloaded */ - if (ast_strlen_zero(cfmtime->who_asked)) { + /* Skip duplicates - this only works because the list is sorted by filename */ + if (!strcmp(cfmtime->filename, prev)) { continue; } - if (++which > a->n && strncmp(cfmtime->filename, a->word, wordlen) == 0) { - completion_value = ast_strdup(cfmtime->filename); - break; + if (!strncmp(cfmtime->filename, a->word, wordlen)) { + if (ast_cli_completion_add(ast_strdup(cfmtime->filename))) { + break; + } } /* Otherwise save that we've seen this filename */ @@ -3963,7 +3965,7 @@ static char *handle_cli_config_reload(struct ast_cli_entry *e, int cmd, struct a } AST_LIST_UNLOCK(&cfmtime_head); - return completion_value; + return NULL; } if (a->argc != 3) { @@ -4034,6 +4036,7 @@ static void config_shutdown(void) int register_config_cli(void) { ast_cli_register_multiple(cli_config, ARRAY_LEN(cli_config)); + /* This is separate from the module load so cleanup can happen very late. */ ast_register_cleanup(config_shutdown); return 0; } @@ -4120,3 +4123,26 @@ int ast_config_hook_register(const char *name, ao2_ref(hook, -1); return 0; } + +static int unload_module(void) +{ + return 0; +} + +static int load_module(void) +{ + if (ast_opt_console) { + ast_verb(0, "[ Initializing Custom Configuration Options ]\n"); + } + + return reload_module() ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SUCCESS; +} + +/* This module explicitly loads before realtime drivers. */ +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "Configuration", + .support_level = AST_MODULE_SUPPORT_CORE, + .load = load_module, + .unload = unload_module, + .reload = reload_module, + .load_pri = 0, +); |