hwmontempsensor: check active state before activation
The activate() function can be called by the createSensors() when host
power state changes, when host goes off and on again, the sensor will be
activated repeatedly and cause coredump.
This commit add the check activation state before activating the sensor,
which reference from PSUSensor[1].
[1] https://gerrit.openbmc.org/c/openbmc/dbus-sensors/+/74727
Tested on Catalina, no more hwmontempsensor service crash when host
power state from off to running.
Change-Id: I72af303fe808538e20b60a5619c036973b3eac91
Signed-off-by: Potin Lai <potin.lai@quantatw.com>
diff --git a/src/hwmon-temp/HwmonTempSensor.cpp b/src/hwmon-temp/HwmonTempSensor.cpp
index eab7349..9ebd6c9 100644
--- a/src/hwmon-temp/HwmonTempSensor.cpp
+++ b/src/hwmon-temp/HwmonTempSensor.cpp
@@ -97,6 +97,11 @@
void HwmonTempSensor::activate(const std::string& newPath,
const std::shared_ptr<I2CDevice>& newI2CDevice)
{
+ if (isActive())
+ {
+ // Avoid activating an active sensor
+ return;
+ }
path = newPath;
i2cDevice = newI2CDevice;
inputDev.open(path, boost::asio::random_access_file::read_only);