Load default config file when user config is invalid 09/168009/1
authorWonnam Jang <wn.jang@samsung.com>
Mon, 15 Jan 2018 11:22:36 +0000 (20:22 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Tue, 23 Jan 2018 10:49:23 +0000 (10:49 +0000)
Change-Id: I0021fefc33e167a256c6ad3f52f0854b4c60987a
Signed-off-by: Wonnam Jang <wn.jang@samsung.com>
(cherry picked from commit bc058016cd72cb627aa9a6d3f51f4c7d3aed8dc2)

common/vc_config_parser.c

index 0048a05..ac89c5a 100644 (file)
@@ -322,7 +322,14 @@ int vc_parser_load_config(vc_config_s** config_info)
 
                        if (VC_RETRY_COUNT == retry_count) {
                                SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to parse file error : %s", VC_CONFIG);
-                               return -1;
+                               doc = xmlParseFile(VC_CONFIG_DEFAULT);
+                               if (NULL == doc) {
+                                       SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to parse file error : %s", VC_CONFIG_DEFAULT);
+                                       xmlCleanupParser();
+                                       return -1;
+                               }
+                               is_default_open = true;
+                               break;
                        }
                }
        }
@@ -426,9 +433,25 @@ int vc_parser_load_config(vc_config_s** config_info)
        g_config_doc = doc;
 
        if (is_default_open) {
-               xmlSaveFile(VC_CONFIG, g_config_doc);
+               int retry_count = 0;
+               int ret = -1;
+               do {
+                       ret = xmlSaveFile(VC_CONFIG, g_config_doc);
+                       if (0 < ret)
+                               break;
+                       retry_count++;
+                       usleep(10000);
+
+                       if (VC_RETRY_COUNT == retry_count) {
+                               SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to save config file: %d", ret);
+                               return -1;
+                       }
+               } while (0 != ret);
+
                if (0 != __vc_config_parser_set_file_mode(VC_CONFIG))
                        SLOG(LOG_ERROR, vc_config_tag(), "[ERROR] Fail to set file mode - %s", VC_CONFIG);
+
+               SLOG(LOG_ERROR, vc_config_tag(), "Default config is changed : pid(%d)", getpid());
        }
 
        return 0;