*/
#include <dlog.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include <vconf.h>
#include "stt_defs.h"
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);
*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;
}