提交 f087248c authored 作者: Brian West's avatar Brian West

FS-6355 - Patch to have .fsxml file be generated atomic to avoid partial reads…

FS-6355 - Patch to have .fsxml file be generated atomic to avoid partial reads when using this file to compare to previous versions/etc.
上级 430b8fca
...@@ -1612,6 +1612,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file) ...@@ -1612,6 +1612,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file)
FILE *write_fd = NULL; FILE *write_fd = NULL;
switch_xml_t xml = NULL; switch_xml_t xml = NULL;
char *new_file = NULL; char *new_file = NULL;
char *new_file_tmp = NULL;
const char *abs, *absw; const char *abs, *absw;
abs = strrchr(file, '/'); abs = strrchr(file, '/');
...@@ -1628,7 +1629,11 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file) ...@@ -1628,7 +1629,11 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file)
goto done; goto done;
} }
if ((write_fd = fopen(new_file, "w+")) == NULL) { if (!(new_file_tmp = switch_mprintf("%s%s%s.fsxml.tmp", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, abs))) {
goto done;
}
if ((write_fd = fopen(new_file_tmp, "w+")) == NULL) {
goto done; goto done;
} }
...@@ -1637,6 +1642,9 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file) ...@@ -1637,6 +1642,9 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file)
if (preprocess(SWITCH_GLOBAL_dirs.conf_dir, file, write_fd, 0) > -1) { if (preprocess(SWITCH_GLOBAL_dirs.conf_dir, file, write_fd, 0) > -1) {
fclose(write_fd); fclose(write_fd);
write_fd = NULL; write_fd = NULL;
if ( rename(new_file_tmp,new_file) ) {
goto done;
}
if ((fd = open(new_file, O_RDONLY, 0)) > -1) { if ((fd = open(new_file, O_RDONLY, 0)) > -1) {
if ((xml = switch_xml_parse_fd(fd))) { if ((xml = switch_xml_parse_fd(fd))) {
if (strcmp(abs, SWITCH_GLOBAL_filenames.conf_name)) { if (strcmp(abs, SWITCH_GLOBAL_filenames.conf_name)) {
...@@ -1662,6 +1670,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file) ...@@ -1662,6 +1670,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file)
close(fd); close(fd);
} }
switch_safe_free(new_file_tmp);
switch_safe_free(new_file); switch_safe_free(new_file);
return xml; return xml;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论