hwmontempsensor: Fix crash on eventHandler signal callback
Previously the device-management logic didn't handle the eventHandler()
case quite right, leading to crashes like the following when
eventHandler()'s call to createSensors() ends up spuriously trying to
re-create sensor devices:
hwmontempsensor[455]: terminate called after throwing an instance of 'boost::wrapexcept<boost::system::system_error>'
hwmontempsensor[455]: what(): open: No such file or directory [system:2 at /usr/include/boost/asio/detail/impl/io_uring_file_service.ipp:61:5 in function 'boost::system::error_code boost::asio::detail::io_uring_file_service::open(implementation_type&, const char*, boost::asio::file_base::flags, boost::system::error_code&)']
To fix this we have instantiateDevices() augment the map it returns to
include all sensor devices (not just newly created ones) and adding a
bool to indicate whether each one was newly instantiated or already
existed. This allows createSensors() to reuse existing I2CDevices when
called by eventHandler() instead of needlessly trying to destroy &
re-create them.
Tested: On romed8hm3 ran hwmontempsensor by hand (to keep systemd from
restarting it) and restarted E-M to trigger an eventHandler() call,
verified that hwmontempsensor didn't crash and kept all sensors
instantiated. Also tested powering the host on and off to verify that
host-power-domain sensors were still torn down and re-created as
appropriate.
Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Change-Id: I576ff6238f45d8e2885790a624fb5c838648c897
diff --git a/include/HwmonTempSensor.hpp b/include/HwmonTempSensor.hpp
index 276f37d..40be3bb 100644
--- a/include/HwmonTempSensor.hpp
+++ b/include/HwmonTempSensor.hpp
@@ -40,6 +40,11 @@
void deactivate(void);
bool isActive(void);
+ std::shared_ptr<I2CDevice> getI2CDevice() const
+ {
+ return i2cDevice;
+ }
+
private:
// Ordering is important here; readBuf is first so that it's not destroyed
// while async operations from other member fields might still be using it.