Fix for mapper errors during logging service restart

There was a race condition while calling mapper from led monitoring after
error logs started persisting, to avoid such errors the callout information is
now extracted from the message received as part of interface added signal.

Resolves openbmc/openbmc#1853

Change-Id: Ie913992bdcb3b1cb93677d64331db34202f8ae72
Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
diff --git a/fault-monitor/fru-fault-monitor.cpp b/fault-monitor/fru-fault-monitor.cpp
index 8bf27f2..dc2f231 100644
--- a/fault-monitor/fru-fault-monitor.cpp
+++ b/fault-monitor/fru-fault-monitor.cpp
@@ -26,13 +26,17 @@
 
 using AssociationList = std::vector<std::tuple<
                         std::string, std::string, std::string>>;
+using Attributes = sdbusplus::message::variant<bool,AssociationList>;
+using AttributeName = std::string;
+using AttributeMap = std::map<AttributeName, Attributes>;
+using PropertyName = std::string;
+using PropertyMap = std::map<PropertyName, AttributeMap>;
+using LogEntryMsg = std::pair<sdbusplus::message::object_path, PropertyMap>;
+
 using MethodErr  =
     sdbusplus::xyz::openbmc_project::Led::Mapper::Error::MethodError;
 using ObjectNotFoundErr =
     sdbusplus::xyz::openbmc_project::Led::Mapper::Error::ObjectNotFoundError;
-using AssociationRetrieveErr =
-    sdbusplus::xyz::openbmc_project::
-    Led::Fru::Monitor::Error::AssociationRetrieveError;
 using InventoryPathErr =
     sdbusplus::xyz::openbmc_project::
     Led::Fru::Monitor::Error::InventoryPathError;
@@ -121,9 +125,9 @@
 {
     auto bus = msg.get_bus();
 
-    sdbusplus::message::object_path obPath;
-    msg.read(obPath);
-    std::string objectPath(std::move(obPath));
+    LogEntryMsg logEntry;
+    msg.read(logEntry);
+    std::string objectPath(std::move(logEntry.first));
 
     std::size_t found = objectPath.find(ELOG_ENTRY);
     if (found == std::string::npos)
@@ -131,44 +135,22 @@
         //Not a new error entry skip
         return;
     }
+    log<level::ERR>(objectPath.c_str());
 
-    std::string service;
-    try
+    auto iter = logEntry.second.find("org.openbmc.Associations");
+    if (iter == logEntry.second.end())
     {
-        service = getService(bus, LOG_PATH);
-    }
-    catch (MethodErr& e)
-    {
-        commit<MethodErr>();
-        return;
-    }
-    catch (ObjectNotFoundErr& e)
-    {
-        commit<ObjectNotFoundErr>();
         return;
     }
 
-    auto method =  bus.new_method_call(service.c_str(), objectPath.c_str(),
-                                       "org.freedesktop.DBus.Properties",
-                                       "Get");
-
-    method.append("org.openbmc.Associations");
-    method.append("associations");
-    auto reply = bus.call(method);
-    if (reply.is_method_error())
+    auto attr = iter->second.find("associations");
+    if (attr == iter->second.end())
     {
-        using namespace xyz::openbmc_project::Led::Fru::Monitor;
-        report<AssociationRetrieveErr>(
-            AssociationRetrieveError::ELOG_ENTRY_PATH(
-                objectPath.c_str()));
         return;
     }
 
-    sdbusplus::message::variant<AssociationList> assoc;
-    reply.read(assoc);
-
-    auto assocs =
-        sdbusplus::message::variant_ns::get<AssociationList>(assoc);
+    auto& assocs =
+        sdbusplus::message::variant_ns::get<AssociationList>(attr->second);
     if (assocs.empty())
     {
         //No associations skip
@@ -181,9 +163,10 @@
         {
             action(bus, std::get<2>(item), true);
             removeWatches.emplace_back(
-                    std::make_unique<Remove>(bus, std::get<2>(item)));
+                std::make_unique<Remove>(bus, std::get<2>(item)));
         }
     }
+
     return;
 }