FruDevice: Fix crash when fru name is duplicated
The path in dbus has prefix "/xyz/openbmc_project/FruDevice/", without
this prefix the regex_match in findIndexForFRU will nevert be true and
cause service crash.
Tested:
Before:
Sevice crash with the following error:
'''
Jan 01 05:33:27 qbmc fru-device[6635]: terminate called after throwing an instance of 'sdbusplus::exception::SdBusError'
Jan 01 05:33:27 qbmc fru-device[6635]: what(): sd_bus_add_object_vtable: org.freedesktop.DBus.Error.FileExists: File exists
'''
After:
Service alive and works good.
'''
root@qbmc:~# busctl tree xyz.openbmc_project.FruDevice | grep x8x8
|-/xyz/openbmc_project/FruDevice/cable_x8x8
`-/xyz/openbmc_project/FruDevice/cable_x8x8_0
'''
Signed-off-by: Jeff Lin <JeffLin2@quantatw.com>
Change-Id: Id0bf3ccb29be8de95d4f17a86ef962b1c30280cb
diff --git a/src/fru_device.cpp b/src/fru_device.cpp
index 1263c02..df97b1b 100644
--- a/src/fru_device.cpp
+++ b/src/fru_device.cpp
@@ -666,7 +666,8 @@
return;
}
- std::string productName = optionalProductName.value();
+ std::string productName =
+ "/xyz/openbmc_project/FruDevice/" + optionalProductName.value();
std::optional<int> index = findIndexForFRU(dbusInterfaceMap, productName);
if (index.has_value())
@@ -675,8 +676,6 @@
productName += std::to_string(++(*index));
}
- productName = "/xyz/openbmc_project/FruDevice/" + productName;
-
std::shared_ptr<sdbusplus::asio::dbus_interface> iface =
objServer.add_interface(productName, "xyz.openbmc_project.FruDevice");
dbusInterfaceMap[std::pair<size_t, size_t>(bus, address)] = iface;