Add configure option to control how fails behave
Different platforms have different requirements for handling
hwmon sysfs access failures.
The default behavior is now that the application will terminate
if a hardware read fails, and rely on systemd restarting it
as a way of doing retries.
The new configure option --enable-remove-from-dbus-on-fail will
cause the application to remove the property permanently from D-Bus
and never try to access it again, but not fail out. This was the
previous (recently added) default behavior.
Change-Id: I6367f2e3e072a2ca9a3da700d4de1b6c34b219ff
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/configure.ac b/configure.ac
index 540491e..68df2bf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -50,6 +50,17 @@
AC_SUBST([OESDK_TESTCASE_FLAGS], [$testcase_flags])
)
+AC_ARG_ENABLE([remove-from-dbus-on-fail],
+ AS_HELP_STRING([--enable-remove-from-dbus-on-fail], [Remove properties from D-Bus on access failures])
+)
+
+AC_ARG_VAR(REMOVE_ON_FAIL, [Remove properties from D-Bus on access failures])
+
+AS_IF([test "x$enable_remove_from_dbus_on_fail" == "xyes"],
+ [REMOVE_ON_FAIL="yes"]
+ AC_DEFINE_UNQUOTED([REMOVE_ON_FAIL], ["$REMOVE_ON_FAIL"], [Remove properties from D-Bus on access failures])
+)
+
AC_ARG_VAR(BUSNAME_PREFIX, [The DBus busname prefix.])
AC_ARG_VAR(SENSOR_ROOT, [The DBus sensors namespace root.])
AS_IF([test "x$BUSNAME_PREFIX" == "x"], [BUSNAME_PREFIX="xyz.openbmc_project.Hwmon"])
diff --git a/mainloop.cpp b/mainloop.cpp
index a07d558..486a175 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -19,6 +19,7 @@
#include <algorithm>
#include <phosphor-logging/elog-errors.hpp>
+#include "config.h"
#include "sensorset.hpp"
#include "hwmon.hpp"
#include "sysfs.hpp"
@@ -293,7 +294,11 @@
auto valueInterface = addValue(i.first, _hwmonRoot, _instance, info);
if (!valueInterface)
{
+#ifdef REMOVE_ON_FAIL
continue; /* skip adding this sensor for now. */
+#else
+ exit(EXIT_FAILURE);
+#endif
}
auto sensorValue = valueInterface->value();
addThreshold<WarningObject>(i.first, sensorValue, info);
@@ -347,7 +352,9 @@
// Polling loop.
while (!_shutdown)
{
+#ifdef REMOVE_ON_FAIL
std::vector<SensorSet::key_type> destroy;
+#endif
// Iterate through all the sensors.
for (auto& i : state)
{
@@ -406,15 +413,21 @@
using namespace sdbusplus::xyz::openbmc_project::Sensor::Device::Error;
commit<ReadFailure>();
+#ifdef REMOVE_ON_FAIL
destroy.push_back(i.first);
+#else
+ exit(EXIT_FAILURE);
+#endif
}
}
}
+#ifdef REMOVE_ON_FAIL
for (auto& i : destroy)
{
state.erase(i);
}
+#endif
// Respond to DBus
_bus.process_discard();