Create error log on fail
Use elog to create error log on fail.
Resolves openbmc/openbmc#1352
Change-Id: I1c362390110c5b3fcae3335a0bd0a7dd11540883
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/image_manager.cpp b/image_manager.cpp
index 235a5d6..bc6c96f 100644
--- a/image_manager.cpp
+++ b/image_manager.cpp
@@ -8,6 +8,9 @@
#include <sys/wait.h>
#include <sys/stat.h>
#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/elog.hpp>
+#include <elog-errors.hpp>
+#include <xyz/openbmc_project/Software/Version/error.hpp>
#include "config.h"
#include "version.hpp"
#include "watch.hpp"
@@ -21,6 +24,7 @@
{
using namespace phosphor::logging;
+using namespace sdbusplus::xyz::openbmc_project::Software::Version::Error;
namespace fs = std::experimental::filesystem;
struct RemovablePath
@@ -40,6 +44,9 @@
{
log<level::ERR>("Error tarball does not exist",
entry("FILENAME=%s", tarFilePath));
+ report<ManifestFileFailure>(xyz::openbmc_project::Software::Version::
+ ManifestFileFailure::PATH(
+ tarFilePath.c_str()));
return -1;
}
@@ -52,6 +59,8 @@
{
log<level::ERR>("Error occured during mkdtemp",
entry("ERRNO=%d", errno));
+ report<InternalFailure>(xyz::openbmc_project::Software::Version::
+ InternalFailure::FAIL("mkdtemp"));
return -1;
}
@@ -70,6 +79,9 @@
// execl only returns on fail
log<level::ERR>("Failed to untar file",
entry("FILENAME=%s", tarFilePath));
+ report<ManifestFileFailure>(xyz::openbmc_project::Software::Version::
+ ManifestFileFailure::PATH(
+ manifestPath.c_str()));
return -1;
}
else if (pid > 0)
@@ -79,6 +91,8 @@
else
{
log<level::ERR>("fork() failed.");
+ report<InternalFailure>(xyz::openbmc_project::Software::Version::
+ InternalFailure::FAIL("fork"));
return -1;
}
@@ -86,6 +100,9 @@
if (!fs::is_regular_file(manifestPath))
{
log<level::ERR>("Error No manifest file");
+ report<ManifestFileFailure>(xyz::openbmc_project::Software::Version::
+ ManifestFileFailure::PATH(
+ manifestPath.c_str()));
return -1;
}
@@ -94,6 +111,9 @@
if (version.empty())
{
log<level::ERR>("Error unable to read version from manifest file");
+ report<ManifestFileFailure>(xyz::openbmc_project::Software::Version::
+ ManifestFileFailure::PATH(
+ manifestPath.c_str()));
return -1;
}
@@ -102,6 +122,9 @@
if (purposeString.empty())
{
log<level::ERR>("Error unable to read purpose from manifest file");
+ report<ManifestFileFailure>(xyz::openbmc_project::Software::Version::
+ ManifestFileFailure::PATH(
+ manifestPath.c_str()));
return -1;
}
@@ -136,6 +159,8 @@
{
log<level::ERR>("Error occured during mkdir",
entry("ERRNO=%d", errno));
+ report<InternalFailure>(xyz::openbmc_project::Software::Version::
+ InternalFailure::FAIL("mkdir"));
return -1;
}
@@ -168,11 +193,15 @@
if (tarFilePath.empty())
{
log<level::ERR>("Error TarFilePath is empty");
+ report<UnTarFailure>(xyz::openbmc_project::Software::Version::
+ UnTarFailure::PATH(tarFilePath.c_str()));
return -1;
}
if (extractDirPath.empty())
{
log<level::ERR>("Error ExtractDirPath is empty");
+ report<UnTarFailure>(xyz::openbmc_project::Software::Version::
+ UnTarFailure::PATH(tarFilePath.c_str()));
return -1;
}
@@ -190,6 +219,8 @@
// execl only returns on fail
log<level::ERR>("Failed to untar file",
entry("FILENAME=%s", tarFilePath));
+ report<UnTarFailure>(xyz::openbmc_project::Software::Version::
+ UnTarFailure::PATH(tarFilePath.c_str()));
return -1;
}
else if (pid > 0)
@@ -199,6 +230,8 @@
else
{
log<level::ERR>("fork() failed.");
+ report<UnTarFailure>(xyz::openbmc_project::Software::Version::
+ UnTarFailure::PATH(tarFilePath.c_str()));
return -1;
}