From: Wonnam Jang Date: Thu, 8 Mar 2018 00:02:04 +0000 (+0900) Subject: Load default config file when user config is invalid X-Git-Tag: accepted/tizen/unified/20180329.125150~2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fstt.git;a=commitdiff_plain;h=463d77c457fe6d7e09182f474a5c465d7c0b9595 Load default config file when user config is invalid Change-Id: Ia34d37a7799c923b1e6127f1bd127868a59a380d Signed-off-by: Wonnam Jang --- diff --git a/common/stt_config_parser.c b/common/stt_config_parser.c index 6786c71..77d0c79 100644 --- a/common/stt_config_parser.c +++ b/common/stt_config_parser.c @@ -12,6 +12,8 @@ */ #include +#include +#include #include #include "stt_defs.h" @@ -319,14 +321,37 @@ int stt_parser_load_config(stt_config_s** config_info) xmlChar *key; bool is_default_open = false; - doc = xmlParseFile(STT_CONFIG); - if (doc == NULL) { + if (0 != access(STT_CONFIG, F_OK)) { doc = xmlParseFile(STT_DEFAULT_CONFIG); if (doc == NULL) { SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_DEFAULT_CONFIG); + xmlCleanupParser(); return -1; } is_default_open = true; + } else { + int retry_count = 0; + + while (NULL == doc) { + doc = xmlParseFile(STT_CONFIG); + if (NULL != doc) { + break; + } + retry_count++; + usleep(10000); + + if (STT_RETRY_COUNT == retry_count) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_CONFIG); + doc = xmlParseFile(STT_DEFAULT_CONFIG); + if (NULL == doc) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to parse file error : %s", STT_DEFAULT_CONFIG); + xmlCleanupParser(); + return -1; + } + is_default_open = true; + break; + } + } } cur = xmlDocGetRootElement(doc); @@ -450,8 +475,33 @@ int stt_parser_load_config(stt_config_s** config_info) *config_info = temp; g_config_doc = doc; - if (is_default_open) - xmlSaveFile(STT_CONFIG, g_config_doc); + if (is_default_open) { + int retry_count = 0; + int ret = -1; + do { + ret = xmlSaveFile(STT_CONFIG, g_config_doc); + if (0 < ret) + break; + retry_count++; + usleep(10000); + + if (STT_RETRY_COUNT == retry_count) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Save result : %d", ret); + return -1; + } + } while (0 != ret); + + /* Set mode */ + if (0 > chmod(STT_CONFIG, 0600)) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to change file mode : %d", ret); + } + + /* Set owner */ + if (0 > chown(STT_CONFIG, 5000, 5000)) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to change file owner : %d", ret); + } + SLOG(LOG_DEBUG, stt_tag(), "Default config is changed : pid(%d)", getpid()); + } return 0; }