Add configure option for how read fails behave
Different platforms have different requirements for handling
hwmon sysfs access failures.
The default behavior is that a read failure leads to the daemon
exiting after some number of read failures. This can be controlled
to then remove the object from the dbus on failure. Now, it can
instead be controlled to return -errno on read failure.
This new behavior to set the value to -errno must be checked by
whatever mechanism is reporting the value.
Change-Id: I50b93aea56f22267da79c9571319f281e24a1e6f
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/configure.ac b/configure.ac
index 7c516f8..0878173 100644
--- a/configure.ac
+++ b/configure.ac
@@ -50,6 +50,7 @@
AC_SUBST([OESDK_TESTCASE_FLAGS], [$testcase_flags])
)
+# When a sensor access fails, just remove the sensor from dbus instead of exiting the daemon.
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])
)
@@ -61,6 +62,19 @@
AC_DEFINE_UNQUOTED([REMOVE_ON_FAIL], ["$REMOVE_ON_FAIL"], [Remove properties from D-Bus on access failures])
)
+# When a sensor read fails, set the Value on dbus with -errno.
+# Incompatible with remove-from-dbus-on-fail.
+AC_ARG_ENABLE([negative-errno-on-fail],
+ AS_HELP_STRING([--enable-negative-errno-on-fail], [Set sensor value to -errno on read failures])
+)
+
+AC_ARG_VAR(NEGATIVE_ERRNO_ON_FAIL, [Set sensor value to -errno on read failures])
+
+AS_IF([test "x$enable_negative_errno_on_fail" == "xyes"],
+ [NEGATIVE_ERRNO_ON_FAIL="yes"]
+ AC_DEFINE_UNQUOTED([NEGATIVE_ERRNO_ON_FAIL], ["$NEGATIVE_ERRNO_ON_FAIL"], [Set sensor value to -errno on read 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 cfa5483..dfba15f 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -157,6 +157,16 @@
int64_t adjustValue(const SensorSet::key_type& sensor, int64_t value)
{
+// Because read doesn't have an out pointer to store errors.
+// let's assume negative values are errors if they have this
+// set.
+#ifdef NEGATIVE_ERRNO_ON_FAIL
+ if (value < 0)
+ {
+ return value;
+ }
+#endif
+
const auto& it = sensorAdjusts.find(sensor);
if (it != sensorAdjusts.end())
{
diff --git a/sysfs.cpp b/sysfs.cpp
index f348be4..5c7dbee 100644
--- a/sysfs.cpp
+++ b/sysfs.cpp
@@ -21,6 +21,7 @@
#include <memory>
#include <phosphor-logging/log.hpp>
#include <thread>
+#include "config.h"
#include "sysfs.hpp"
using namespace std::string_literals;
@@ -361,6 +362,9 @@
!retries)
{
// Not a retryable error or out of retries.
+#ifdef NEGATIVE_ERRNO_ON_FAIL
+ return -rc;
+#endif
// Work around GCC bugs 53984 and 66145 for callers by
// explicitly raising system_error here.