control - Ensure `nameHasOwner` set on all group members

It was found that `nameHasOwner` method calls upon fan control starting
was not setting all group members' service owned states. This was due to
skipping group members if they were hosted by the same service, which
actually caused a problem later when the action would be run looking at
the service state for all groups members. With this fix all group
members get an initial service owned state thru `nameHasOwner`.

Change-Id: Icd8e16e0a2235522aa531a629a82aa2af47c5199
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/triggers/init.cpp b/control/json/triggers/init.cpp
index 2a9ce9e..183caea 100644
--- a/control/json/triggers/init.cpp
+++ b/control/json/triggers/init.cpp
@@ -66,6 +66,7 @@
 
 void nameHasOwner(Manager* mgr, const Group& group)
 {
+    bool hasOwner = false;
     std::string lastName = "";
     for (const auto& member : group.getMembers())
     {
@@ -78,18 +79,21 @@
             {
                 servName = mgr->getService(member, intf);
             }
-            if (!servName.empty() && lastName != servName)
+            if (!servName.empty())
             {
-                // Member not provided by same service as last group member
-                lastName = servName;
-                auto hasOwner = util::SDBusPlus::callMethodAndRead<bool>(
-                    mgr->getBus(), "org.freedesktop.DBus",
-                    "/org/freedesktop/DBus", "org.freedesktop.DBus",
-                    "NameHasOwner", servName);
+                if (lastName != servName)
+                {
+                    // Member not provided by same service as last group member
+                    lastName = servName;
+                    hasOwner = util::SDBusPlus::callMethodAndRead<bool>(
+                        mgr->getBus(), "org.freedesktop.DBus",
+                        "/org/freedesktop/DBus", "org.freedesktop.DBus",
+                        "NameHasOwner", servName);
+                }
                 // Update service name owner state of group object
                 mgr->setOwner(member, servName, intf, hasOwner);
             }
-            if (servName.empty())
+            else
             {
                 // Path and/or interface configured does not exist on dbus?
                 // TODO How to handle this? Create timer to keep checking for
@@ -106,18 +110,18 @@
             if (!servName.empty())
             {
                 // Failed to get service name owner state
-                mgr->setOwner(member, servName, intf, false);
+                hasOwner = false;
+                mgr->setOwner(member, servName, intf, hasOwner);
             }
             else
             {
                 // Path and/or interface configured does not exist on dbus?
                 // TODO How to handle this? Create timer to keep checking for
                 // object/service to appear? When to stop checking?
-                log<level::ERR>(
-                    fmt::format(
-                        "Unable to get service name for path {}, interface {}",
-                        member, intf)
-                        .c_str());
+                log<level::ERR>(fmt::format("Unable to get service({}) owner "
+                                            "state for path {}, interface {}",
+                                            servName, member, intf)
+                                    .c_str());
                 throw dme;
             }
         }