hwmon-temp-sensor: Support sensor with missing labels
Erase sensorName from hwmonName even if it is not included in the
`Labels` property. This makes sure that all hwmonNames that it parsed
will be removed and allows us to support missing labels when we don't
want to expose all sensors.
Currently the hwmon temp sensors forces all sensor labels to be
required even when we don't want to expose all of them.
With
```
{
"Address": "0x4e",
"Bus": "$bus",
"Name": "test0",
"Name1": "test1",
"Name2": "test2",
"Name3": "test3",
"Labels": ["temp4"],
"Type": "MAX31730"
},
```
It will have
```
$ /tmp/hwmontempsensor &
error getting SpecialMode status No route to host
malloc(): unsorted double linked list corrupted
-sh: line 438: 20466 Aborted (core dumped) /tmp/hwmontempsensor
```
It needs the `Labels` to be `["temp1, "temp2", "temp3", "temp4"]` for
this to work properly.
With the fix to the daemon it doesn't need it anymore.
Tested:
Working and didn't crash
```
busctl tree xyz.openbmc_project.HwmonTempSensor
`-/xyz
`-/xyz/openbmc_project
`-/xyz/openbmc_project/sensors
`-/xyz/openbmc_project/sensors/temperature
`-/xyz/openbmc_project/sensors/temperature/test3
```
Change-Id: I926b76dbb2777bc3e0f273b001139cd468617e63
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/src/HwmonTempMain.cpp b/src/HwmonTempMain.cpp
index aea29ab..1d2fb5c 100644
--- a/src/HwmonTempMain.cpp
+++ b/src/HwmonTempMain.cpp
@@ -429,10 +429,11 @@
thisSensorParameters, pollRate, interfacePath,
readState);
sensor->setupRead();
- hwmonName.erase(
- remove(hwmonName.begin(), hwmonName.end(), sensorName),
- hwmonName.end());
}
+ hwmonName.erase(
+ remove(hwmonName.begin(), hwmonName.end(), sensorName),
+ hwmonName.end());
+
// Looking for keys like "Name1" for temp2_input,
// "Name2" for temp3_input, etc.
int i = 0;
@@ -479,10 +480,11 @@
std::move(thresholds), thisSensorParameters,
pollRate, interfacePath, readState);
sensor->setupRead();
- hwmonName.erase(remove(hwmonName.begin(),
- hwmonName.end(), sensorName),
- hwmonName.end());
}
+
+ hwmonName.erase(
+ remove(hwmonName.begin(), hwmonName.end(), sensorName),
+ hwmonName.end());
}
if (hwmonName.empty())
{