Revert "sensor: remove exception in error path"
This reverts commit 379b11316d55b114bdb1bfc5a49839b09ade9038, bringing
it back into line with expected ASIO callback behavior, as documented in
Ic3a36027fa95a77469439b296a1497634cfe030f. The reverted commit was based
on a misunderstanding of the ASIO error handling path.
Tested: With accompanying sdbusplus change, was able to override sensor
value only when ValidationUnsecure mode was enabled, and proper error
response was returned:
root@openbmc:~# busctl set-property xyz.openbmc_project.IpmbSensor \
/xyz/openbmc_project/sensors/temperature/SSB_Temp \
xyz.openbmc_project.Sensor.Value Value d 52
Failed to set property Value on interface xyz.openbmc_project.Sensor.Value: Not allowed to set property value.
root@openbmc:~# busctl set-property xyz.openbmc_project.SpecialMode \
/xyz/openbmc_project/security/special_mode \
xyz.openbmc_project.Security.SpecialMode SpecialMode s \
xyz.openbmc_project.Control.Security.SpecialMode.Modes.ValidationUnsecure
root@openbmc:~# busctl set-property xyz.openbmc_project.IpmbSensor \
/xyz/openbmc_project/sensors/temperature/SSB_Temp \
xyz.openbmc_project.Sensor.Value Value d 52
root@openbmc:~#
Change-Id: I05c41318954d5d1549752c5ef2c227f3f22a45d3
Signed-off-by: Jonathan Doman <jonathan.doman@intel.com>
diff --git a/include/sensor.hpp b/include/sensor.hpp
index 404b261..236c6e7 100644
--- a/include/sensor.hpp
+++ b/include/sensor.hpp
@@ -5,6 +5,7 @@
#include <Thresholds.hpp>
#include <Utils.hpp>
#include <sdbusplus/asio/object_server.hpp>
+#include <sdbusplus/exception.hpp>
#include <limits>
#include <memory>
@@ -37,6 +38,22 @@
double maxCollected = 0.0;
};
+struct SetSensorError : sdbusplus::exception_t
+{
+ const char* name() const noexcept override
+ {
+ return "xyz.openbmc_project.Common.Errors.NotAllowed";
+ }
+ const char* description() const noexcept override
+ {
+ return "Not allowed to set property value.";
+ }
+ int get_errno() const noexcept override
+ {
+ return EACCES;
+ }
+};
+
struct Sensor
{
Sensor(const std::string& name,
@@ -205,17 +222,10 @@
{
if (!internalSet)
{
- if (insecureSensorOverride == 0)
- { // insecure sesnor override.
- if (isSensorSettable == false)
- { // sensor is not settable.
- if (getManufacturingMode() == false)
- { // manufacture mode is not enable.
- std::cerr << "Sensor " << name
- << ": Not allowed to set property value.\n";
- return -EACCES;
- }
- }
+ if (insecureSensorOverride == 0 && !isSensorSettable &&
+ !getManufacturingMode())
+ {
+ throw SetSensorError();
}
oldValue = newValue;
@@ -234,7 +244,7 @@
{
oldValue = newValue;
}
- return 1;
+ return true;
}
void setInitialProperties(const std::string& unit,
@@ -252,7 +262,7 @@
sensorInterface->register_property("MaxValue", maxValue);
sensorInterface->register_property("MinValue", minValue);
sensorInterface->register_property(
- "Value", value, [&](const double& newValue, double& oldValue) {
+ "Value", value, [this](const double& newValue, double& oldValue) {
return setSensorValue(newValue, oldValue);
});