nmi: Use libpdbg directly

This avoids calling DBus to run a systemd unit that is effectively a
shell script when we already have libpdbg on the system anyway.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I9a36c38f075d402b9bc406433475a371d1cdbe62
diff --git a/nmi_interface.cpp b/nmi_interface.cpp
index aea38ae..fcce451 100644
--- a/nmi_interface.cpp
+++ b/nmi_interface.cpp
@@ -16,6 +16,8 @@
 
 #include "nmi_interface.hpp"
 
+#include <libpdbg.h>
+
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/elog.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
@@ -33,24 +35,27 @@
 void NMI::nMI()
 {
     using namespace phosphor::logging;
-    using sdbusplus::exception::SdBusError;
     using InternalFailure =
         sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
 
-    constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
-    constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
-    constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
+    struct pdbg_target* target;
 
-    auto method = bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
-                                      SYSTEMD_INTERFACE, "StartUnit");
-    method.append("nmi.service", "replace");
-    try
+    pdbg_for_each_class_target("thread", target)
     {
-        bus.call_noreply(method);
+        if (pdbg_target_probe(target) != PDBG_TARGET_ENABLED)
+            continue;
+
+        if (thread_stop(target) < 0 || !thread_status(target).quiesced)
+        {
+            log<level::ERR>("Failed to stop all threads");
+            report<InternalFailure>();
+            return;
+        }
     }
-    catch (const SdBusError& e)
+
+    if (thread_sreset_all() < 0)
     {
-        log<level::ALERT>("Error in starting NMI service. ");
+        log<level::ERR>("Failed to sreset all threads");
         report<InternalFailure>();
     }
 }