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/item_updater.cpp b/item_updater.cpp
index 2fdbc31..3ea954c 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -19,6 +19,7 @@
 #include <queue>
 #include <set>
 #include <string>
+#include <system_error>
 
 namespace phosphor
 {
@@ -194,7 +195,8 @@
 
     // Read os-release from folders under /media/ to get
     // BMC Software Versions.
-    for (const auto& iter : fs::directory_iterator(MEDIA_DIR))
+    std::error_code ec;
+    for (const auto& iter : fs::directory_iterator(MEDIA_DIR, ec))
     {
         auto activationState = server::Activation::Activations::Active;
         static const auto BMC_RO_PREFIX_LEN = strlen(BMC_ROFS_PREFIX);
@@ -206,14 +208,16 @@
             // Get the version to calculate the id
             fs::path releaseFile(OS_RELEASE_FILE);
             auto osRelease = iter.path() / releaseFile.relative_path();
-            if (!fs::is_regular_file(osRelease))
+            if (!fs::is_regular_file(osRelease, ec))
             {
 #ifdef BMC_STATIC_DUAL_IMAGE
                 // For dual image, it is possible that the secondary image is
                 // empty or contains invalid data, ignore such case.
-                info("Unable to find osRelease: {PATH}", "PATH", osRelease);
+                info("Unable to find osRelease: {PATH}: {ERROR_MSG}", "PATH",
+                     osRelease, "ERROR_MSG", ec.message());
 #else
-                error("Failed to read osRelease: {PATH}", "PATH", osRelease);
+                error("Failed to read osRelease: {PATH}: {ERROR_MSG}", "PATH",
+                      osRelease, "ERROR_MSG", ec.message());
 
                 // Try to get the version id from the mount directory name and
                 // call to delete it as this version may be corrupted. Dynamic