diff options
author | Jeff Peeler <jpeeler@digium.com> | 2010-01-27 18:29:49 +0000 |
---|---|---|
committer | Jeff Peeler <jpeeler@digium.com> | 2010-01-27 18:29:49 +0000 |
commit | a170cd28e0c2a5635f33fec7cf08f304ca7ef95f (patch) | |
tree | 2f8be97f4da2d33e2bcaa8caddcb6f0037931465 /main | |
parent | 630b8027c36546796a05e27a32c06823e1780ab1 (diff) |
Add new option to asterisk.conf (lockconfdir) to protect conf dir during reloads
(closes issue #16358)
Reported by: raarts
Patches:
lockconfdir.diff uploaded by raarts (license 937)
modified by me
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@243551 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main')
-rw-r--r-- | main/asterisk.c | 2 | ||||
-rw-r--r-- | main/loader.c | 23 |
2 files changed, 25 insertions, 0 deletions
diff --git a/main/asterisk.c b/main/asterisk.c index 5ccfd200b..4b691d873 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -2997,6 +2997,8 @@ static void ast_readconfig(void) ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_FORCE_BLACK_BACKGROUND); } else if (!strcasecmp(v->name, "hideconnect")) { ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_HIDE_CONSOLE_CONNECT); + } else if (!strcasecmp(v->name, "lockconfdir")) { + ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_LOCK_CONFIG_DIR); } } for (v = ast_variable_browse(cfg, "compat"); v; v = v->next) { diff --git a/main/loader.c b/main/loader.c index 8c0067d92..99c9f124f 100644 --- a/main/loader.c +++ b/main/loader.c @@ -49,6 +49,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/dsp.h" #include "asterisk/udptl.h" #include "asterisk/heap.h" +#include "asterisk/app.h" #include <dlfcn.h> @@ -652,6 +653,22 @@ int ast_module_reload(const char *name) } ast_lastreloadtime = ast_tvnow(); + if (ast_opt_lock_confdir) { + int try; + int res; + for (try = 1, res = AST_LOCK_TIMEOUT; try < 6 && (res == AST_LOCK_TIMEOUT); try++) { + res = ast_lock_path(ast_config_AST_CONFIG_DIR); + if (res == AST_LOCK_TIMEOUT) { + ast_log(LOG_WARNING, "Failed to grab lock on %s, try %d\n", ast_config_AST_CONFIG_DIR, try); + } + } + if (res != AST_LOCK_SUCCESS) { + ast_verbose("Cannot grab lock on %s\n", ast_config_AST_CONFIG_DIR); + ast_mutex_unlock(&reloadlock); + return -1; + } + } + /* Call "predefined" reload here first */ for (i = 0; reload_classes[i].name; i++) { if (!name || !strcasecmp(name, reload_classes[i].name)) { @@ -661,6 +678,9 @@ int ast_module_reload(const char *name) } if (name && res) { + if (ast_opt_lock_confdir) { + ast_unlock_path(ast_config_AST_CONFIG_DIR); + } ast_mutex_unlock(&reloadlock); return res; } @@ -695,6 +715,9 @@ int ast_module_reload(const char *name) } AST_LIST_UNLOCK(&module_list); + if (ast_opt_lock_confdir) { + ast_unlock_path(ast_config_AST_CONFIG_DIR); + } ast_mutex_unlock(&reloadlock); return res; |