bmc: merge update and prepare systemd
The update systemd and prepare systemd were effectively the same, and
this makes the systemd action generic.
Tested: Not tested beyond unit-tests continuing to pass.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I8070731e53bfd6cdafb1d74d9db652f20341985e
diff --git a/bmc/general_systemd.cpp b/bmc/general_systemd.cpp
index ff51f39..5b9fb87 100644
--- a/bmc/general_systemd.cpp
+++ b/bmc/general_systemd.cpp
@@ -103,4 +103,54 @@
return mode;
}
+std::unique_ptr<TriggerableActionInterface>
+ SystemdNoFile::CreateSystemdNoFile(sdbusplus::bus::bus&& bus,
+ const std::string& service,
+ const std::string& mode)
+{
+ return std::make_unique<SystemdNoFile>(std::move(bus), service, mode);
+}
+
+bool SystemdNoFile::trigger()
+{
+ static constexpr auto systemdService = "org.freedesktop.systemd1";
+ static constexpr auto systemdRoot = "/org/freedesktop/systemd1";
+ static constexpr auto systemdInterface = "org.freedesktop.systemd1.Manager";
+
+ auto method = bus.new_method_call(systemdService, systemdRoot,
+ systemdInterface, "StartUnit");
+ method.append(triggerService);
+ method.append(mode);
+
+ try
+ {
+ bus.call_noreply(method);
+ state = ActionStatus::running;
+ return true;
+ }
+ catch (const sdbusplus::exception::SdBusError& ex)
+ {
+ /* TODO: Once logging supports unit-tests, add a log message to test
+ * this failure.
+ */
+ state = ActionStatus::failed;
+ return false;
+ }
+}
+
+void SystemdNoFile::abort()
+{
+ return;
+}
+
+ActionStatus SystemdNoFile::status()
+{
+ return state;
+}
+
+const std::string SystemdNoFile::getMode() const
+{
+ return mode;
+}
+
} // namespace ipmi_flash