cpusensor: access inventoryIfaces by reference instead of by value
Previously this lookup was copying the value out of the map instead of
taking a reference to it, so the subsequent reassignment didn't actually
update the contents of the map.
In certain unusual situations involving repeated sensor discovery
attempts (the case in question being a host CPU whose PECI
implementation doesn't support reading DIMM temperatures, preventing the
sensor from ever reaching the READY state and thus PECI pings continuing
indefinitely), this can lead to a host reboot causing the cpusensor
daemon to attempt to re-register a dbus interface it had already
registered previously, followed shortly by a crash:
terminate called after throwing an instance of 'sdbusplus::exception::SdBusError'
what(): sd_bus_add_object_vtable: org.freedesktop.DBus.Error.FileExists: File exists
With this patch in place, cpusensor runs smoothly across a host reboot.
Change-Id: Ie4ceb9e42db2237a8a08e7c52953b016d1e8b56e
Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Suggested-by: Ed Tanous <ed@tanous.net>
diff --git a/src/CPUSensorMain.cpp b/src/CPUSensorMain.cpp
index f304e3f..6106bc0 100644
--- a/src/CPUSensorMain.cpp
+++ b/src/CPUSensorMain.cpp
@@ -142,7 +142,7 @@
if (cpu.state != State::OFF)
{
available = true;
- std::shared_ptr<sdbusplus::asio::dbus_interface> iface =
+ std::shared_ptr<sdbusplus::asio::dbus_interface>& iface =
inventoryIfaces[cpu.name];
if (iface != nullptr)
{