control: Catch GetManagedObjects exceptions
The get_managed_objects action makes a GetManagedObjects D-Bus call to
put D-bus properties from a service into the cache.
Handle exceptions thrown by it in case it was called from a
name_owner_changed trigger when the service went off of D-Bus, which
would cause it to fail.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I18ebcea327578073780b4658c8a1d897cbfa20e5
diff --git a/control/json/actions/get_managed_objects.cpp b/control/json/actions/get_managed_objects.cpp
index cf7f3a3..eb5600e 100644
--- a/control/json/actions/get_managed_objects.cpp
+++ b/control/json/actions/get_managed_objects.cpp
@@ -42,37 +42,45 @@
{
for (const auto& member : group.getMembers())
{
- std::vector<std::string> objMgrPaths;
-
- const auto& service =
- zone.getManager()->getService(member, group.getInterface());
-
- if (!service.empty())
+ try
{
- objMgrPaths = zone.getManager()->getPaths(
- service, "org.freedesktop.DBus.ObjectManager");
- }
- else
- {
- continue;
- }
+ std::vector<std::string> objMgrPaths;
- // Look for the ObjectManager as an ancestor of the path.
- auto hasObjMgr =
- std::any_of(objMgrPaths.begin(), objMgrPaths.end(),
- [member](const auto& path) {
- return member.find(path) != std::string::npos;
- });
+ const auto& service =
+ zone.getManager()->getService(member, group.getInterface());
- if (!hasObjMgr || services.find(service) == services.end())
- {
- if (hasObjMgr)
+ if (!service.empty())
{
- services.insert(service);
+ objMgrPaths = zone.getManager()->getPaths(
+ service, "org.freedesktop.DBus.ObjectManager");
+ }
+ else
+ {
+ continue;
}
- zone.getManager()->addObjects(member, group.getInterface(),
- group.getProperty());
+ // Look for the ObjectManager as an ancestor of the path.
+ auto hasObjMgr = std::any_of(
+ objMgrPaths.begin(), objMgrPaths.end(),
+ [member](const auto& path) {
+ return member.find(path) != std::string::npos;
+ });
+
+ if (!hasObjMgr || services.find(service) == services.end())
+ {
+ if (hasObjMgr)
+ {
+ services.insert(service);
+ }
+
+ zone.getManager()->addObjects(member, group.getInterface(),
+ group.getProperty());
+ }
+ }
+ catch (const std::exception& e)
+ {
+ // May have been called from a name_owner_changed trigger
+ // and the service may have been lost.
}
}
}