Fix the core dump by using filesystem error_code

The currently used filesystem method will cause an exception if the
file system is damaged for some reason, resulting in a core dump of
the process.
So the overloaded method with the error_code parameter should be used
here to ensure that the process core dump will not be caused after an
exception is thrown.

Fixes: openbmc/phosphor-bmc-code-mgmt#12

Tested: built phosphor-bmc-code-mgmt successfully and CI passes.

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I329f78b481cb466e755bc1b78562583620f561c2
diff --git a/sync_watch.cpp b/sync_watch.cpp
index e84d061..ecf6cef 100644
--- a/sync_watch.cpp
+++ b/sync_watch.cpp
@@ -9,6 +9,7 @@
 
 #include <filesystem>
 #include <fstream>
+#include <system_error>
 
 namespace phosphor
 {
@@ -53,8 +54,9 @@
         return;
     }
 
+    std::error_code ec;
     auto syncfile = fs::path(SYNC_LIST_DIR_PATH) / SYNC_LIST_FILE_NAME;
-    if (fs::exists(syncfile))
+    if (fs::exists(syncfile, ec))
     {
         std::string line;
         std::ifstream file(syncfile.c_str());
@@ -98,7 +100,8 @@
         // Watch was removed, re-add it if file still exists.
         if (event->mask & IN_IGNORED)
         {
-            if (fs::exists(syncWatch->fileMap[event->wd]))
+            std::error_code ec;
+            if (fs::exists(syncWatch->fileMap[event->wd], ec))
             {
                 syncWatch->addInotifyWatch(syncWatch->fileMap[event->wd]);
             }