Capture calls to the getDbusProperty method
We should catch the exception to prevent a coredump when calling the
getDbusProperty method.
Change-Id: I83a8b48f8007989279dd34cfc4f29ca96bb7965e
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
diff --git a/sensordatahandler.cpp b/sensordatahandler.cpp
index ae0b878..60b5c9a 100644
--- a/sensordatahandler.cpp
+++ b/sensordatahandler.cpp
@@ -77,21 +77,32 @@
const auto& interfaceList = sensorInfo.propertyInterfaces;
- for (const auto& interface : interfaceList)
+ for (const auto& [intf, propertyMap] : interfaceList)
{
- for (const auto& property : interface.second)
+ for (const auto& [property, values] : propertyMap)
{
- auto propValue = ipmi::getDbusProperty(
- bus, service, path, interface.first, property.first);
-
- for (const auto& value : std::get<OffsetValueMap>(property.second))
+ try
{
- if (propValue == value.second.assert)
+ auto propValue =
+ ipmi::getDbusProperty(bus, service, path, intf, property);
+
+ for (const auto& value : std::get<OffsetValueMap>(values))
{
- setOffset(value.first, &response);
- break;
+ if (propValue == value.second.assert)
+ {
+ setOffset(value.first, &response);
+ break;
+ }
}
}
+ catch (const std::exception& e)
+ {
+ lg2::error(
+ "mapDbusToAssertion: Failed to get property, service: {SERVICE},"
+ " path: {PATH}, interface: {INTERFACE}, property name: {PRONAME}: {ERROR}",
+ "SERVICE", service, "PATH", path, "INTERFACE", intf,
+ "PRONAME", property, "ERROR", e);
+ }
}
}
@@ -110,22 +121,32 @@
const auto& interfaceList = sensorInfo.propertyInterfaces;
- for (const auto& interface : interfaceList)
+ for (const auto& [intf, propertyMap] : interfaceList)
{
- for (const auto& property : interface.second)
+ for (const auto& [property, values] : propertyMap)
{
- auto propValue =
- ipmi::getDbusProperty(bus, service, sensorInfo.sensorPath,
- interface.first, property.first);
-
- for (const auto& value : std::get<OffsetValueMap>(property.second))
+ try
{
- if (propValue == value.second.assert)
+ auto propValue = ipmi::getDbusProperty(
+ bus, service, sensorInfo.sensorPath, intf, property);
+
+ for (const auto& value : std::get<OffsetValueMap>(values))
{
- setReading(value.first, &response);
- break;
+ if (propValue == value.second.assert)
+ {
+ setReading(value.first, &response);
+ break;
+ }
}
}
+ catch (const std::exception& e)
+ {
+ lg2::error(
+ "mapDbusToEventdata2: Failed to get property, service: {SERVICE},"
+ " path: {PATH}, interface: {INTERFACE}, property name: {PRONAME}: {ERROR}",
+ "SERVICE", service, "PATH", sensorInfo.sensorPath,
+ "INTERFACE", intf, "PRONAME", property, "ERROR", e);
+ }
}
}
diff --git a/sensordatahandler.hpp b/sensordatahandler.hpp
index db80a69..3d56971 100644
--- a/sensordatahandler.hpp
+++ b/sensordatahandler.hpp
@@ -176,16 +176,25 @@
GetSensorResponse response{};
enableScanning(&response);
+ try
+ {
+ auto service = ipmi::getService(bus, sensorInfo.sensorInterface,
+ sensorInfo.sensorPath);
+ auto propValue = ipmi::getDbusProperty(
+ bus, service, sensorInfo.sensorPath,
+ sensorInfo.propertyInterfaces.begin()->first,
+ sensorInfo.propertyInterfaces.begin()->second.begin()->first);
- auto service = ipmi::getService(bus, sensorInfo.sensorInterface,
- sensorInfo.sensorPath);
-
- auto propValue = ipmi::getDbusProperty(
- bus, service, sensorInfo.sensorPath,
- sensorInfo.propertyInterfaces.begin()->first,
- sensorInfo.propertyInterfaces.begin()->second.begin()->first);
-
- setAssertionBytes(static_cast<uint16_t>(std::get<T>(propValue)), &response);
+ setAssertionBytes(static_cast<uint16_t>(std::get<T>(propValue)),
+ &response);
+ }
+ catch (const std::exception& e)
+ {
+ lg2::error(
+ "Failed to call readingAssertion, path: {PATH}, interface: {INTERFACE}: {ERROR}",
+ "PATH", sensorInfo.sensorPath, "INTERFACE",
+ sensorInfo.sensorInterface, "ERROR", e);
+ }
return response;
}
@@ -236,13 +245,26 @@
}
#endif
- auto propValue = ipmi::getDbusProperty(
- bus, service, sensorInfo.sensorPath,
- sensorInfo.propertyInterfaces.begin()->first,
- sensorInfo.propertyInterfaces.begin()->second.begin()->first);
+ double value{};
+ try
+ {
+ auto propValue = ipmi::getDbusProperty(
+ bus, service, sensorInfo.sensorPath,
+ sensorInfo.propertyInterfaces.begin()->first,
+ sensorInfo.propertyInterfaces.begin()->second.begin()->first);
- double value = std::get<T>(propValue) *
- std::pow(10, sensorInfo.scale - sensorInfo.exponentR);
+ value = std::get<T>(propValue) *
+ std::pow(10, sensorInfo.scale - sensorInfo.exponentR);
+ }
+ catch (const std::exception& e)
+ {
+ lg2::error(
+ "Failed to call readingData, path: {PATH}, interface: {INTERFACE}: {ERROR}",
+ "PATH", sensorInfo.sensorPath, "INTERFACE",
+ sensorInfo.sensorInterface, "ERROR", e);
+ return response;
+ }
+
int32_t rawData =
(value - sensorInfo.scaledOffset) / sensorInfo.coefficientM;