Don't exit on probe not found error

We should check the error and not exit for file not
found error, all other errors still exit. Remove mapper
cache as c++ mapper seems reliable now. Also make sure
to clear pending probes on failure.

Tested-By: Stopped Fru-Device, Started Entity Manager,
           waited and then started Fru-Device. Overlays
           were correctly added after the fact.
Change-Id: Ia6ed5ad8ca5a4aa8a8340ba67ee1ac826fc82ef8
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/src/EntityManager.cpp b/src/EntityManager.cpp
index c46ee72..c93fb60 100644
--- a/src/EntityManager.cpp
+++ b/src/EntityManager.cpp
@@ -108,10 +108,6 @@
                      std::shared_ptr<sdbusplus::asio::connection> connection,
                      std::string &interface)
 {
-    // todo: this is only static because the mapper is unreliable as of today
-    static boost::container::flat_map<std::string,
-                                      boost::container::flat_set<std::string>>
-        connections;
 
     // store reference to pending callbacks so we don't overwhelm services
     static boost::container::flat_map<
@@ -137,20 +133,20 @@
 
     // find all connections in the mapper that expose a specific type
     connection->async_method_call(
-        [&, connection, interface](boost::system::error_code &ec,
-                                   const GetSubTreeType &interfaceSubtree) {
-            auto &interfaceConnections = connections[interface];
+        [connection, interface, probe](boost::system::error_code &ec,
+                                       const GetSubTreeType &interfaceSubtree) {
+            boost::container::flat_set<std::string> interfaceConnections;
             if (ec)
             {
-                std::cerr
-                    << "Error communicating to mapper, using cached data if "
-                       "available\n";
-                if (interfaceConnections.empty())
+                pendingProbes[interface].clear();
+                if (ec.value() == ENOENT)
                 {
-                    // if we can't get the mapper data on the first run,
-                    // something is very wrong
-                    std::exit(EXIT_FAILURE);
+                    return; // wasn't found by mapper
                 }
+                std::cerr << "Error communicating to mapper.\n";
+
+                // if we can't communicate to the mapper something is very wrong
+                std::exit(EXIT_FAILURE);
             }
             else
             {
@@ -167,7 +163,7 @@
             for (const auto &conn : interfaceConnections)
             {
                 connection->async_method_call(
-                    [&, conn,
+                    [conn,
                      interface](boost::system::error_code &ec,
                                 const ManagedObjectType &managedInterface) {
                         if (ec)
@@ -421,12 +417,6 @@
         lastCommand = probeType != PROBE_TYPES.end()
                           ? probeType->second
                           : probe_type_codes::FALSE_T;
-
-        if (!foundProbe)
-        {
-            std::cerr << "Illegal probe type " << probe << "\n";
-            return false;
-        }
     }
 
     // probe passed, but empty device
@@ -565,25 +555,22 @@
         iface->register_property(propertyName, value);
         return;
     }
-    iface->register_property(
-        propertyName, value,
-        [&systemConfiguration,
-         jsonPointerString{std::string(jsonPointerString)}](
-            const PropertyType &newVal, PropertyType &val) {
-            val = newVal;
-            if (!setJsonFromPointer(jsonPointerString, val,
-                                    systemConfiguration))
-            {
-                std::cerr << "error setting json field\n";
-                return -1;
-            }
-            if (writeJsonFiles(systemConfiguration))
-            {
-                std::cerr << "error setting json file\n";
-                return 1;
-            }
+    iface->register_property(propertyName, value, [
+        &systemConfiguration, jsonPointerString{std::string(jsonPointerString)}
+    ](const PropertyType &newVal, PropertyType &val) {
+        val = newVal;
+        if (!setJsonFromPointer(jsonPointerString, val, systemConfiguration))
+        {
+            std::cerr << "error setting json field\n";
             return -1;
-        });
+        }
+        if (writeJsonFiles(systemConfiguration))
+        {
+            std::cerr << "error setting json file\n";
+            return 1;
+        }
+        return -1;
+    });
 }
 
 // adds simple json types to interface's properties