summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2018-07-09 22:34:33 -0400
committerAdriana Kobylak <anoo@us.ibm.com>2018-07-11 12:28:48 -0500
commitcca7a7c8733a22f12d89dc0fd2d355f4fb9b4bb4 (patch)
tree1a4b3919d821160e5f5c0d31b1bbe738bc36f112
parent6522cdcb109b02377d8a45bafa5524599014d406 (diff)
downloadphosphor-dbus-monitor-cca7a7c8733a22f12d89dc0fd2d355f4fb9b4bb4.zip
phosphor-dbus-monitor-cca7a7c8733a22f12d89dc0fd2d355f4fb9b4bb4.tar.gz
propertywatch: Improve error handling
Handle exceptions from the sdbusplus method call API. A number of method calls are made at application startup. First the mapper is queried and then host services directly to obtain initial values for the property cache. In either case a missing object is sometimes expected and tolerated (in a logical sense) without issue. Eat the new exceptions in these scenarios and avoid a program crash. Change-Id: Id79d28b2da997f3c545b86c21932e271e3df8bb3 Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
-rw-r--r--src/propertywatchimpl.hpp32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/propertywatchimpl.hpp b/src/propertywatchimpl.hpp
index 003ee37..6500a15 100644
--- a/src/propertywatchimpl.hpp
+++ b/src/propertywatchimpl.hpp
@@ -47,11 +47,22 @@ void PropertyWatch<DBusInterfaceType>::start()
// Do a query to populate the cache. Start with a mapper query.
// The specific services are queried below.
- const std::vector<std::string> queryInterfaces; // all interfaces
- auto mapperResp =
- DBusInterfaceType::template callMethodAndRead<GetObject>(
- MAPPER_BUSNAME, MAPPER_PATH, MAPPER_INTERFACE, "GetObject",
- path, queryInterfaces);
+ auto getObjectFromMapper = [](const auto& path) {
+ const std::vector<std::string> queryInterfaces; // all interfaces
+ try
+ {
+ return DBusInterfaceType::template callMethodAndRead<GetObject>(
+ MAPPER_BUSNAME, MAPPER_PATH, MAPPER_INTERFACE, "GetObject",
+ path, queryInterfaces);
+ }
+ catch (const sdbusplus::exception::SdBusError&)
+ {
+ // Paths in the configuration may not exist yet. Prime those
+ // later, when/if InterfacesAdded occurs.
+ return GetObject();
+ }
+ };
+ auto mapperResp = getObjectFromMapper(path);
for (const auto& i : interfaces)
{
@@ -87,7 +98,16 @@ void PropertyWatch<DBusInterfaceType>::start()
}
// Delegate type specific property updates to subclasses.
- updateProperties(busName, path, interface);
+ try
+ {
+ updateProperties(busName, path, interface);
+ }
+ catch (const sdbusplus::exception::SdBusError&)
+ {
+ // If for some reason the path has gone away since
+ // the mapper lookup we'll simply try again if/when
+ // InterfacesAdded occurs the next time it shows up.
+ }
}
}
}
OpenPOWER on IntegriCloud