summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJayanth Othayoth <ojayanth@in.ibm.com>2017-09-20 00:04:22 -0500
committerJayanth Othayoth <ojayanth@in.ibm.com>2017-09-20 00:05:26 -0500
commit9c7f03a7fd810288186fba4d86dc341c0c067716 (patch)
tree19701a2b9f202c424a8d1f6cb3ad86017c309d93
parent05aae8bc28cd81cdfea29eaa3cdb89b817b03faf (diff)
downloadphosphor-logging-9c7f03a7fd810288186fba4d86dc341c0c067716.tar.gz
phosphor-logging-9c7f03a7fd810288186fba4d86dc341c0c067716.zip
phosphor-log-manager: Fix for deserialize cereal exception
This commit provides a fix for an issue in which the cereal deserialize() would crash the phosphor-log-manager incase persistence file is empty in restore path. Resolves openbmc/openbmc#2337 Change-Id: Id9d8c066d0dc50cba62a67060c1ee8d43d046ff1 Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
-rw-r--r--elog_serialize.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/elog_serialize.cpp b/elog_serialize.cpp
index 72dc295..f8c40e1 100644
--- a/elog_serialize.cpp
+++ b/elog_serialize.cpp
@@ -3,7 +3,9 @@
#include <cereal/types/tuple.hpp>
#include <cereal/archives/binary.hpp>
#include <fstream>
+
#include "elog_serialize.hpp"
+#include <phosphor-logging/log.hpp>
namespace phosphor
{
@@ -65,14 +67,23 @@ fs::path serialize(const Entry& e, const fs::path& dir)
bool deserialize(const fs::path& path, Entry& e)
{
- if (fs::exists(path))
+ try
+ {
+ if (fs::exists(path))
+ {
+ std::ifstream is(path.c_str(), std::ios::in | std::ios::binary);
+ cereal::BinaryInputArchive iarchive(is);
+ iarchive(e);
+ return true;
+ }
+ return false;
+ }
+ catch(cereal::Exception& e)
{
- std::ifstream is(path.c_str(), std::ios::in | std::ios::binary);
- cereal::BinaryInputArchive iarchive(is);
- iarchive(e);
- return true;
+ log<level::ERR>(e.what());
+ fs::remove(path);
+ return false;
}
- return false;
}
} // namespace logging
OpenPOWER on IntegriCloud