From ce6a795a8ecc7755290ea4bcef4bf3340a331b49 Mon Sep 17 00:00:00 2001 From: Marri Devender Rao Date: Sun, 11 Feb 2018 08:45:00 -0600 Subject: Fix failure in reading power value during PowerOff state D-Bus sensor object to read power value is not created during PowerOff state. Fixed to return 0 power value if sensor object is not present. Change-Id: Ibe340cab0483c7a711081197b932aaba0408d333 Signed-off-by: Marri Devender Rao --- dcmihandler.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/dcmihandler.cpp b/dcmihandler.cpp index 11befdc..bfc8466 100644 --- a/dcmihandler.cpp +++ b/dcmihandler.cpp @@ -1037,18 +1037,28 @@ int64_t getPowerReading(sdbusplus::bus::bus& bus) elog(); } - auto service = ipmi::getService(bus, SENSOR_VALUE_INTF, objectPath); - - //Read the sensor value and scale properties - auto properties = ipmi::getAllDbusProperties( - bus, service, objectPath, SENSOR_VALUE_INTF); - auto power = properties[SENSOR_VALUE_PROP].get(); - auto scale = properties[SENSOR_SCALE_PROP].get(); + // Return default value if failed to read from D-Bus object + int64_t power = 0; + try + { + auto service = ipmi::getService(bus, SENSOR_VALUE_INTF, objectPath); - // Power reading needs to be scaled with the Scale value using the formula - // Value * 10^Scale. - power *= std::pow(10, scale); + //Read the sensor value and scale properties + auto properties = ipmi::getAllDbusProperties( + bus, service, objectPath, SENSOR_VALUE_INTF); + auto value = properties[SENSOR_VALUE_PROP].get(); + auto scale = properties[SENSOR_SCALE_PROP].get(); + // Power reading needs to be scaled with the Scale value using the + // formula Value * 10^Scale. + power = value * std::pow(10, scale); + } + catch (std::exception& e) + { + log("Failure to read power value from D-Bus object", + entry("OBJECT_PATH=%s", objectPath), + entry("INTERFACE=%s", SENSOR_VALUE_INTF)); + } return power; } -- cgit v1.2.1