boot-block: remove blocking error on erase

When an entry is erased, remove it from the blocking array. This will
result in the d-bus object at the /xyz/openbmc_project/logging/blockX
path being deleted as well.

Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: Ib49073532588d25c4ae357917ecd6339a70d8c1e
diff --git a/log_manager.cpp b/log_manager.cpp
index 72a8f3c..929ff5d 100644
--- a/log_manager.cpp
+++ b/log_manager.cpp
@@ -352,6 +352,18 @@
     }
 }
 
+void Manager::checkAndRemoveBlockingError(uint32_t entryId)
+{
+    auto it = find_if(
+        blockingErrors.begin(), blockingErrors.end(),
+        [&](std::unique_ptr<Block>& obj) { return obj->entryId == entryId; });
+    if (it != blockingErrors.end())
+    {
+        blockingErrors.erase(it);
+    }
+    return;
+}
+
 void Manager::erase(uint32_t entryId)
 {
     auto entryFound = entries.find(entryId);
@@ -400,6 +412,8 @@
         }
         entries.erase(entryFound);
 
+        checkAndRemoveBlockingError(entryId);
+
         for (auto& remove : Extensions::getDeleteFunctions())
         {
             try
diff --git a/log_manager.hpp b/log_manager.hpp
index 8f8ff82..700a39a 100644
--- a/log_manager.hpp
+++ b/log_manager.hpp
@@ -201,6 +201,12 @@
      */
     bool isCalloutPresent(const Entry& entry);
 
+    /** @brief Check (and remove) entry being erased from blocking errors
+     *
+     * @param[in] entryId - The entry that is being erased
+     */
+    void checkAndRemoveBlockingError(uint32_t entryId);
+
   private:
     /*
      * @fn _commit()
diff --git a/test/elog_quiesce_test.cpp b/test/elog_quiesce_test.cpp
index 3eb2a3d..1f1cdeb 100644
--- a/test/elog_quiesce_test.cpp
+++ b/test/elog_quiesce_test.cpp
@@ -140,6 +140,22 @@
     manager.checkQuiesceOnError(elog);
     // Created error with callout so expect a blocking error now
     EXPECT_EQ(manager.getBlockingErrSize(), 1);
+
+    // Now delete the error and make sure the object and entry go away
+    EXPECT_CALL(sdbusMock, sd_bus_emit_object_removed(testing::_, testing::_))
+        .Times(testing::AnyNumber());
+    EXPECT_CALL(sdbusMock,
+                sd_bus_emit_object_removed(
+                    testing::_, testing::HasSubstr(
+                                    "/xyz/openbmc_project/logging/block100")))
+        .Times(1);
+
+    // Make sure nothing happens within invalid id
+    manager.checkAndRemoveBlockingError(id + 1);
+    EXPECT_EQ(manager.getBlockingErrSize(), 1);
+
+    manager.checkAndRemoveBlockingError(id);
+    EXPECT_EQ(manager.getBlockingErrSize(), 0);
 }
 
 } // namespace test