Support reading socket-only systemd unit info

Current code will only read unit info like unit name and instance name
from service unit. For socket-only unit, these fields are blank. This
patch adds support to read these fields from socket units.

Tested:
1. Existing entries in generated srvcfg-mgr.json is the same as before
2. Unit and instance name of socket-only units can be successfully read

Change-Id: Ibb4d75231f1767f2164d95294e126dd649d466f0
Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
diff --git a/src/main.cpp b/src/main.cpp
index c4f7e71..b5d7cf2 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -127,19 +127,17 @@
                 auto& value = it->second;
                 if (type == UnitType::service)
                 {
-                    std::get<static_cast<int>(monitorElement::unitName)>(
-                        value) = unitName;
-                    std::get<static_cast<int>(monitorElement::instanceName)>(
-                        value) = instanceName;
                     std::get<static_cast<int>(monitorElement::serviceObjPath)>(
-                        value) = objectPath;
+                        value) = objectPath.str;
                 }
                 else if (type == UnitType::socket)
                 {
                     std::get<static_cast<int>(monitorElement::socketObjPath)>(
-                        value) = objectPath;
+                        value) = objectPath.str;
                 }
+                continue;
             }
+            // If not grouped with any existing entry, create a new one
             if (type == UnitType::service)
             {
                 unitsToMonitor.emplace(instantiatedUnitName,
@@ -148,9 +146,9 @@
             }
             else if (type == UnitType::socket)
             {
-                unitsToMonitor.emplace(
-                    instantiatedUnitName,
-                    std::make_tuple("", "", "", objectPath.str));
+                unitsToMonitor.emplace(instantiatedUnitName,
+                                       std::make_tuple(unitName, instanceName,
+                                                       "", objectPath.str));
             }
         }
     }