Add the "config reload <conffile>" command, which allows you to tell Asterisk
authorTilghman Lesher <tilghman@meg.abyt.es>
Wed, 26 Mar 2008 18:39:06 +0000 (18:39 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Wed, 26 Mar 2008 18:39:06 +0000 (18:39 +0000)
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

16 files changed:
channels/iax2-provision.c
include/asterisk/config.h
include/asterisk/udptl.h
main/asterisk.c
main/cdr.c
main/config.c
main/dnsmgr.c
main/dsp.c
main/enum.c
main/features.c
main/http.c
main/loader.c
main/logger.c
main/manager.c
main/rtp.c
main/udptl.c

index 5b52a09..fa5cdb0 100644 (file)
@@ -497,7 +497,7 @@ int iax_provision_reload(int reload)
                cur->dead = 1;
                cur = cur->next;
        }
-       cfg = ast_config_load("iaxprov.conf", config_flags);
+       cfg = ast_config_load2("iaxprov.conf", "chan_iax2", config_flags);
        if (cfg != NULL && cfg != CONFIG_STATUS_FILEUNCHANGED) {
                /* Load as appropriate */
                cat = ast_category_browse(cfg, NULL);
index 793bb89..da88e21 100644 (file)
@@ -97,7 +97,7 @@ struct ast_config_engine {
  */
 struct ast_config *ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags);
 
-#define ast_config_load(filename, flags)       ast_config_load2(filename, __FILE__, flags)
+#define ast_config_load(filename, flags)       ast_config_load2(filename, AST_MODULE, flags)
 
 /*! \brief Destroys a config 
  * \param config pointer to config data structure
index 74fcf35..0d9e8d8 100644 (file)
@@ -118,7 +118,7 @@ void ast_udptl_stop(struct ast_udptl *udptl);
 
 void ast_udptl_init(void);
 
-void ast_udptl_reload(void);
+int ast_udptl_reload(void);
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }
index aac00c9..ce62850 100644 (file)
@@ -2509,11 +2509,11 @@ static void ast_readconfig(void)
        } found = { 0, 0 };
 
        if (ast_opt_override_config) {
-               cfg = ast_config_load(ast_config_AST_CONFIG_FILE, config_flags);
+               cfg = ast_config_load2(ast_config_AST_CONFIG_FILE, "" /* core, can't reload */, config_flags);
                if (!cfg)
                        ast_log(LOG_WARNING, "Unable to open specified master config file '%s', using built-in defaults\n", ast_config_AST_CONFIG_FILE);
        } else 
-               cfg = ast_config_load(config, config_flags);
+               cfg = ast_config_load2(config, "" /* core, can't reload */, config_flags);
 
        /* init with buildtime config */
        ast_copy_string(cfg_paths.config_dir, DEFAULT_CONFIG_DIR, sizeof(cfg_paths.config_dir));
@@ -2756,7 +2756,7 @@ static void run_startup_commands(void)
        struct ast_flags cfg_flags = { 0 };
        struct ast_variable *v;
 
-       if (!(cfg = ast_config_load("cli.conf", cfg_flags)))
+       if (!(cfg = ast_config_load2("cli.conf", "" /* core, can't reload */, cfg_flags)))
                return;
 
        fd = open("/dev/null", O_RDWR);
index 5b68e8f..3c45baf 100644 (file)
@@ -1330,7 +1330,7 @@ static int do_reload(int reload)
        int res=0;
        struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 
-       if ((config = ast_config_load("cdr.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+       if ((config = ast_config_load2("cdr.conf", "cdr", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
                return 0;
 
        ast_mutex_lock(&cdr_batch_lock);
index 0c09cc8..29e2e12 100644 (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() 
index 0989f63..a258328 100644 (file)
@@ -360,7 +360,7 @@ static int do_reload(int loading)
        int was_enabled;
        int res = -1;
 
-       if ((config = ast_config_load("dnsmgr.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+       if ((config = ast_config_load2("dnsmgr.conf", "dnsmgr", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
                return 0;
 
        /* ensure that no refresh cycles run while the reload is in progress */
index 8e16567..3d639a3 100644 (file)
@@ -1548,7 +1548,7 @@ static int _dsp_init(int reload)
        struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
        struct ast_config *cfg;
 
-       cfg = ast_config_load(CONFIG_FILE_NAME, config_flags);
+       cfg = ast_config_load2(CONFIG_FILE_NAME, "dsp", config_flags);
 
        if (cfg && cfg != CONFIG_STATUS_FILEUNCHANGED) {
                const char *value;
index 3f4266a..78dafb6 100644 (file)
@@ -606,7 +606,7 @@ static int private_enum_init(int reload)
        struct ast_variable *v;
        struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 
-       if ((cfg = ast_config_load("enum.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+       if ((cfg = ast_config_load2("enum.conf", "enum", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
                return 0;
 
        /* Destroy existing list */
index 4521985..2c0aab6 100644 (file)
@@ -2594,7 +2594,7 @@ static int load_config(void)
        atxferdropcall = DEFAULT_ATXFER_DROP_CALL;
        atxfercallbackretries = DEFAULT_ATXFER_CALLBACK_RETRIES;
 
-       cfg = ast_config_load("features.conf", config_flags);
+       cfg = ast_config_load2("features.conf", "features", config_flags);
        if (!cfg) {
                ast_log(LOG_WARNING,"Could not load features.conf\n");
                return 0;
index 7b11e9c..9e8735b 100644 (file)
@@ -1087,7 +1087,7 @@ static int __ast_http_load(int reload)
        struct http_uri_redirect *redirect;
        struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 
-       if ((cfg = ast_config_load("http.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
+       if ((cfg = ast_config_load2("http.conf", "http", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
                return 0;
        }
 
index e05bac4..baddec7 100644 (file)
@@ -48,6 +48,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/lock.h"
 #include "asterisk/features.h"
 #include "asterisk/dsp.h"
+#include "asterisk/udptl.h"
 
 #ifdef DLFCNCOMPAT
 #include "asterisk/dlfcn-compat.h"
@@ -251,6 +252,7 @@ static struct reload_classes {
        { "logger",     logger_reload },
        { "features",   ast_features_reload },
        { "dsp",        ast_dsp_reload},
+       { "udptl",      ast_udptl_reload },
        { NULL,         NULL }
 };
 
@@ -786,7 +788,7 @@ int load_modules(unsigned int preload_only)
                embedded_module_list.first = NULL;
        }
 
-       if (!(cfg = ast_config_load(AST_MODULE_CONFIG, config_flags))) {
+       if (!(cfg = ast_config_load2(AST_MODULE_CONFIG, "" /* core, can't reload */, config_flags))) {
                ast_log(LOG_WARNING, "No '%s' found, no modules will be loaded.\n", AST_MODULE_CONFIG);
                goto done;
        }
index 072a23b..b7c517f 100644 (file)
@@ -325,7 +325,7 @@ static void init_logger_chain(int reload, int locked)
        const char *s;
        struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 
-       if ((cfg = ast_config_load("logger.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+       if ((cfg = ast_config_load2("logger.conf", "logger", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
                return;
 
        /* delete our list of log channels */
index e54238c..e8eebf9 100644 (file)
@@ -1089,7 +1089,7 @@ static int action_getconfig(struct mansession *s, const struct message *m)
                astman_send_error(s, m, "Filename not specified");
                return 0;
        }
-       if (!(cfg = ast_config_load(fn, config_flags))) {
+       if (!(cfg = ast_config_load2(fn, "manager", config_flags))) {
                astman_send_error(s, m, "Config file not found");
                return 0;
        }
@@ -1130,7 +1130,7 @@ static int action_listcategories(struct mansession *s, const struct message *m)
                astman_send_error(s, m, "Filename not specified");
                return 0;
        }
-       if (!(cfg = ast_config_load(fn, config_flags))) {
+       if (!(cfg = ast_config_load2(fn, "manager", config_flags))) {
                astman_send_error(s, m, "Config file not found or file has invalid syntax");
                return 0;
        }
@@ -1184,7 +1184,7 @@ static int action_getconfigjson(struct mansession *s, const struct message *m)
                return 0;
        }
 
-       if (!(cfg = ast_config_load(fn, config_flags))) {
+       if (!(cfg = ast_config_load2(fn, "manager", config_flags))) {
                astman_send_error(s, m, "Config file not found");
                return 0;
        }
@@ -1355,7 +1355,7 @@ static int action_updateconfig(struct mansession *s, const struct message *m)
                astman_send_error(s, m, "Filename not specified");
                return 0;
        }
-       if (!(cfg = ast_config_load(sfn, config_flags))) {
+       if (!(cfg = ast_config_load2(sfn, "manager", config_flags))) {
                astman_send_error(s, m, "Config file not found");
                return 0;
        }
@@ -3757,7 +3757,7 @@ static int __init_manager(int reload)
                /* Append placeholder event so master_eventq never runs dry */
                append_event("Event: Placeholder\r\n\r\n", 0);
        }
-       if ((cfg = ast_config_load("manager.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+       if ((cfg = ast_config_load2("manager.conf", "manager", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
                return 0;
 
        displayconnects = 1;
@@ -3839,7 +3839,7 @@ static int __init_manager(int reload)
        AST_RWLIST_WRLOCK(&users);
 
        /* First, get users from users.conf */
-       ucfg = ast_config_load("users.conf", config_flags);
+       ucfg = ast_config_load2("users.conf", "manager", config_flags);
        if (ucfg && (ucfg != CONFIG_STATUS_FILEUNCHANGED)) {
                const char *hasmanager;
                int genhasmanager = ast_true(ast_variable_retrieve(ucfg, "general", "hasmanager"));
index 1647074..ff2b83f 100644 (file)
@@ -4192,7 +4192,7 @@ static int __ast_rtp_reload(int reload)
        const char *s;
        struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 
-       if ((cfg = ast_config_load("rtp.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+       if ((cfg = ast_config_load2("rtp.conf", "rtp", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
                return 0;
 
        rtpstart = 5000;
index 2f0e1fb..7dea4d8 100644 (file)
@@ -1224,7 +1224,7 @@ static void __ast_udptl_reload(int reload)
        const char *s;
        struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 
-       if ((cfg = ast_config_load("udptl.conf", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
+       if ((cfg = ast_config_load2("udptl.conf", "udptl", config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
                return;
 
        udptlstart = 4500;
@@ -1297,9 +1297,10 @@ static void __ast_udptl_reload(int reload)
        ast_verb(2, "UDPTL allocating from port range %d -> %d\n", udptlstart, udptlend);
 }
 
-void ast_udptl_reload(void)
+int ast_udptl_reload(void)
 {
        __ast_udptl_reload(1);
+       return 0;
 }
 
 void ast_udptl_init(void)