commit | 379b11316d55b114bdb1bfc5a49839b09ade9038 | [log] [tgz] |
---|---|---|
author | Patrick Williams <patrick@stwcx.xyz> | Thu Sep 02 05:42:25 2021 -0500 |
committer | Patrick Williams <patrick@stwcx.xyz> | Thu Sep 02 05:48:50 2021 -0500 |
tree | bc88c168344d5f148da0120c060d7515a946e74b | |
parent | 2932a7bb38e49ee79ec87114927b3d95a82f18cd [diff] [blame] |
sensor: remove exception in error path Any ASIO property callback handler should *not* throw an exception. This will crash the application because there is nothing in the ASIO stack that catches the exception and turns it into an sd_bus_error. It is also invalid to construct an SdBusError because it is an internal class type of sdbusplus. Instead of throwing the bad exception and crashing the sensor application, print an error message and return the intended -ERRNO (EACCES), so that sd_bus will pass it back along to the dbus client as an sd_bus_error response. The behavior of the underlying sd_bus library can be observed at: https://github.com/systemd/systemd/blob/a4121e965f43bc323ec3c0ac212cee9d339f7be0/src/libsystemd/sd-bus/bus-objects.c#L520 https://github.com/systemd/systemd/blob/a4121e965f43bc323ec3c0ac212cee9d339f7be0/src/libsystemd/sd-bus/bus-objects.c#L683 Signed-off-by: Patrick Williams <patrick@stwcx.xyz> Change-Id: Icd6dfc30eb6aa4d17c846b28c69ca4a5aa253d61
diff --git a/include/sensor.hpp b/include/sensor.hpp index b98241b..3ac7774 100644 --- a/include/sensor.hpp +++ b/include/sensor.hpp
@@ -182,8 +182,9 @@ { // sensor is not settable. if (getManufacturingMode() == false) { // manufacture mode is not enable. - throw sdbusplus::exception::SdBusError( - -EACCES, "Not allow set porperty value."); + std::cerr << "Sensor " << name + << ": Not allowed to set property value.\n"; + return -EACCES; } } }