Correct app data file name

Corrected app data file name and also set priority for global variable.

Change-Id: Ia9c256506fdaeea2c7fd1bde7c1a58f40f2448be
Signed-off-by: Vijay Khemka <vijaykhemka@fb.com>
diff --git a/include/appcommands.hpp b/include/appcommands.hpp
index ba61ffa..55cf81b 100644
--- a/include/appcommands.hpp
+++ b/include/appcommands.hpp
@@ -44,7 +44,7 @@
 #define SIZE_LAST_BOOT_TIME 4
 #define SIZE_PCIE_PORT_CONFIG 2
 
-#define JSON_DATA_FILE "/etc/appData.json"
+#define JSON_APP_DATA_FILE "/etc/appData.json"
 #define KEY_SYSFW_VER "sysfw_ver_server"
 #define KEY_BIOS_BOOT_LEN "bios_boot_list_len"
 
diff --git a/src/appcommands.cpp b/src/appcommands.cpp
index 5aecea7..a6cbc5e 100644
--- a/src/appcommands.cpp
+++ b/src/appcommands.cpp
@@ -44,7 +44,7 @@
 // TODO: Need to store this info after identifying proper storage
 static uint8_t globEna = 0x09;
 static SysInfoParam sysInfoParams;
-nlohmann::json appData;
+nlohmann::json appData __attribute__((init_priority(101)));
 
 void printGUID(uint8_t *guid, off_t offset)
 {
@@ -242,8 +242,9 @@
 
 void flush_app_data()
 {
-    std::ofstream file(JSON_DATA_FILE);
+    std::ofstream file(JSON_APP_DATA_FILE);
     file << appData;
+    file.close();
     return;
 }
 
@@ -442,9 +443,12 @@
 void registerAPPFunctions()
 {
     /* Get App data stored in json file */
-    std::ifstream file(JSON_DATA_FILE);
+    std::ifstream file(JSON_APP_DATA_FILE);
     if (file)
+    {
         file >> appData;
+        file.close();
+    }
 
     ipmiPrintAndRegister(NETFUN_APP, CMD_APP_GET_SELFTEST_RESULTS, NULL,
                          ipmiAppGetSTResults,