Ignore non-existent units
In systemd, if a non-existent unit is referenced by other unit, it will
be listed in ListUnits response. This commit ignores these non-existent
entries to prevent performing operations on them.
Tested:
In dropbear.socket, there is a Conflicts=dropbear.service which creates
a non-existent service entry. With this commit, it will not be added to
the service object path in /etc/srvcfg-mgr.json.
Change-Id: I2ce360ea3a0b10f527672d1601ae4d6234c1a9aa
Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
diff --git a/src/main.cpp b/src/main.cpp
index b5d7cf2..3d67800 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -107,6 +107,13 @@
// managed, irrespective of instance name.
for (const auto& unit : listUnits)
{
+ // Ignore non-existent units
+ if (std::get<static_cast<int>(ListUnitElements::loadState)>(unit) ==
+ loadStateNotFound)
+ {
+ continue;
+ }
+
const auto& fullUnitName =
std::get<static_cast<int>(ListUnitElements::name)>(unit);
auto [unitName, type, instanceName] =