mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-03-05 18:13:27 +00:00
improve reloadxml code to fix potential issue
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4630 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
940bf73b72
commit
3ec36c1f51
@ -1083,37 +1083,40 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_root(void)
|
|||||||
SWITCH_DECLARE(switch_xml_t) switch_xml_open_root(uint8_t reload, const char **err)
|
SWITCH_DECLARE(switch_xml_t) switch_xml_open_root(uint8_t reload, const char **err)
|
||||||
{
|
{
|
||||||
char path_buf[1024];
|
char path_buf[1024];
|
||||||
uint8_t hasmain = 0;
|
uint8_t hasmain = 0, errcnt = 0;
|
||||||
|
switch_xml_t new_main;
|
||||||
|
|
||||||
switch_mutex_lock(XML_LOCK);
|
switch_mutex_lock(XML_LOCK);
|
||||||
|
|
||||||
if (MAIN_XML_ROOT) {
|
if (MAIN_XML_ROOT) {
|
||||||
switch_xml_t xml;
|
|
||||||
hasmain++;
|
hasmain++;
|
||||||
|
|
||||||
if (!reload) {
|
if (!reload) {
|
||||||
switch_mutex_unlock(XML_LOCK);
|
switch_mutex_unlock(XML_LOCK);
|
||||||
return switch_xml_root();
|
return switch_xml_root();
|
||||||
}
|
}
|
||||||
xml = MAIN_XML_ROOT;
|
|
||||||
MAIN_XML_ROOT = NULL;
|
|
||||||
switch_thread_rwlock_wrlock(RWLOCK);
|
switch_thread_rwlock_wrlock(RWLOCK);
|
||||||
switch_xml_free(xml);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(path_buf, sizeof(path_buf), "%s%s%s", SWITCH_GLOBAL_dirs.conf_dir, SWITCH_PATH_SEPARATOR, "freeswitch.xml");
|
snprintf(path_buf, sizeof(path_buf), "%s%s%s", SWITCH_GLOBAL_dirs.conf_dir, SWITCH_PATH_SEPARATOR, "freeswitch.xml");
|
||||||
if ((MAIN_XML_ROOT = switch_xml_parse_file(path_buf))) {
|
if ((new_main = switch_xml_parse_file(path_buf))) {
|
||||||
*err = switch_xml_error(MAIN_XML_ROOT);
|
*err = switch_xml_error(new_main);
|
||||||
|
|
||||||
if (!switch_strlen_zero(*err)) {
|
if (!switch_strlen_zero(*err)) {
|
||||||
switch_xml_free(MAIN_XML_ROOT);
|
switch_xml_free(new_main);
|
||||||
MAIN_XML_ROOT = NULL;
|
new_main = NULL;
|
||||||
|
errcnt++;
|
||||||
} else {
|
} else {
|
||||||
|
switch_xml_t old_root;
|
||||||
*err = "Success";
|
*err = "Success";
|
||||||
|
old_root = MAIN_XML_ROOT;
|
||||||
|
MAIN_XML_ROOT = new_main;
|
||||||
switch_set_flag(MAIN_XML_ROOT, SWITCH_XML_ROOT);
|
switch_set_flag(MAIN_XML_ROOT, SWITCH_XML_ROOT);
|
||||||
|
switch_xml_free(old_root);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
*err = "Cannot Open log directory or XML Root!";
|
*err = "Cannot Open log directory or XML Root!";
|
||||||
|
errcnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasmain) {
|
if (hasmain) {
|
||||||
@ -1121,7 +1124,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_open_root(uint8_t reload, const char **e
|
|||||||
}
|
}
|
||||||
switch_mutex_unlock(XML_LOCK);
|
switch_mutex_unlock(XML_LOCK);
|
||||||
|
|
||||||
return switch_xml_root();
|
return errcnt == 0 ? switch_xml_root() : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user