crit-service: create bmc dump on failure

When a critical service fails, request a BMC dump to assist in debug of
why the service failed.

Tested:
- Caused critical service to fail and verified bmc dump was created

Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: I2f56af0ee43b84e4142cc29f3c9ddbec053b8334
diff --git a/systemd_target_signal.cpp b/systemd_target_signal.cpp
index c44e52f..cc3cf4c 100644
--- a/systemd_target_signal.cpp
+++ b/systemd_target_signal.cpp
@@ -19,6 +19,26 @@
 
 using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
 
+void SystemdTargetLogging::createBmcDump()
+{
+    auto method = this->bus.new_method_call(
+        "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump/bmc",
+        "xyz.openbmc_project.Dump.Create", "CreateDump");
+    method.append(
+        std::vector<
+            std::pair<std::string, std::variant<std::string, uint64_t>>>());
+    try
+    {
+        this->bus.call_noreply(method);
+    }
+    catch (const sdbusplus::exception::exception& e)
+    {
+        error("Failed to create BMC dump, exception:{ERROR}", "ERROR", e);
+        // just continue, this is error path anyway so we're just collecting
+        // what we can
+    }
+}
+
 void SystemdTargetLogging::logError(const std::string& errorLog,
                                     const std::string& result,
                                     const std::string& unit)
@@ -71,6 +91,9 @@
             info(
                 "Monitored systemd service has hit an error, unit:{UNIT}, result:{RESULT}",
                 "UNIT", unit, "RESULT", result);
+
+            // Generate a BMC dump when a critical service fails
+            createBmcDump();
             return (std::string{
                 "xyz.openbmc_project.State.Error.CriticalServiceFailure"});
         }
diff --git a/systemd_target_signal.hpp b/systemd_target_signal.hpp
index c46425a..27e0334 100644
--- a/systemd_target_signal.hpp
+++ b/systemd_target_signal.hpp
@@ -72,6 +72,9 @@
                                    const std::string& result);
 
   private:
+    /** @brief Call phosphor-dump-manager to create BMC dump */
+    void createBmcDump();
+
     /** @brief Call phosphor-logging to create error
      *
      * @param[in]  error      - The error to log