crit-service: create error on failed service
This enhances the existing code to support logging an error when a
monitored service fails. The same systemd event is triggered for a
target failure and a service failure so no new logic is needed in
that area.
Tested:
- Repeatedly killed the host-state service until its unit went into the
failed state. Verified this was detected and the expected log was
created.
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: I459dd8c35ceddec986336fee635fdf691257f758
diff --git a/systemd_target_signal.hpp b/systemd_target_signal.hpp
index d9a58c7..8674ca5 100644
--- a/systemd_target_signal.hpp
+++ b/systemd_target_signal.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include "systemd_service_parser.hpp"
#include "systemd_target_parser.hpp"
#include <sdbusplus/bus.hpp>
@@ -28,9 +29,10 @@
virtual ~SystemdTargetLogging() = default;
SystemdTargetLogging(const TargetErrorData& targetData,
+ const ServiceMonitorData& serviceData,
sdbusplus::bus::bus& bus) :
targetData(targetData),
- bus(bus),
+ serviceData(serviceData), bus(bus),
systemdJobRemovedSignal(
bus,
sdbusplus::bus::match::rules::type::signal() +
@@ -66,8 +68,8 @@
*
* @return valid pointer to error to log, otherwise nullptr
*/
- const std::string* processError(const std::string& unit,
- const std::string& result);
+ const std::string processError(const std::string& unit,
+ const std::string& result);
private:
/** @brief Call phosphor-logging to create error
@@ -100,6 +102,9 @@
/** @brief Systemd targets to monitor and error logs to create */
const TargetErrorData& targetData;
+ /** @brief Systemd targets to monitor and error logs to create */
+ const ServiceMonitorData& serviceData;
+
/** @brief Persistent sdbusplus DBus bus connection. */
sdbusplus::bus::bus& bus;