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.cpp b/systemd_target_signal.cpp
index 25089ef..9f778d5 100644
--- a/systemd_target_signal.cpp
+++ b/systemd_target_signal.cpp
@@ -42,8 +42,8 @@
}
}
-const std::string* SystemdTargetLogging::processError(const std::string& unit,
- const std::string& result)
+const std::string SystemdTargetLogging::processError(const std::string& unit,
+ const std::string& result)
{
auto targetEntry = this->targetData.find(unit);
if (targetEntry != this->targetData.end())
@@ -56,10 +56,25 @@
info(
"Monitored systemd unit has hit an error, unit:{UNIT}, result:{RESULT}",
"UNIT", unit, "RESULT", result);
- return (&targetEntry->second.errorToLog);
+ return (targetEntry->second.errorToLog);
}
}
- return nullptr;
+
+ // Check if it's in our list of services to monitor
+ if (std::find(this->serviceData.begin(), this->serviceData.end(), unit) !=
+ this->serviceData.end())
+ {
+ if (result == "failed")
+ {
+ info(
+ "Monitored systemd service has hit an error, unit:{UNIT}, result:{RESULT}",
+ "UNIT", unit, "RESULT", result);
+ return (std::string{
+ "xyz.openbmc_project.State.Error.CriticalServiceFailure"});
+ }
+ }
+
+ return (std::string{});
}
void SystemdTargetLogging::systemdUnitChange(sdbusplus::message::message& msg)
@@ -74,12 +89,12 @@
// In most cases it will just be success, in which case just return
if (result != "done")
{
- const std::string* error = processError(unit, result);
+ const std::string error = processError(unit, result);
// If this is a monitored error then log it
- if (error)
+ if (!error.empty())
{
- logError(*error, result);
+ logError(error, result);
}
}
return;