psusensor: Fix incorrect event sensors
The event sensors are expected to track the sysfs paths that are in
limitEventMatch.
However, the code incorrectly adds paths like `tempx_max` into the event
sensors because it replace `input` with `xxx_alarm` and check if the
path exists or not.
When the path does not include `input`, it is not changed at all and the
path does exist, thus it is added into the event sensors incorrectly.
Fix it by checking the above case and skip such path.
Tested: Verify the sensors like `temp1_max` is not added into the event
sensors anymore.
Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: I219cb8ef966fc00c121359b0b1bcfc2b68cf0216
diff --git a/src/PSUSensorMain.cpp b/src/PSUSensorMain.cpp
index 0f7d17e..83c0c58 100644
--- a/src/PSUSensorMain.cpp
+++ b/src/PSUSensorMain.cpp
@@ -33,6 +33,7 @@
#include <iostream>
#include <regex>
#include <string>
+#include <string_view>
#include <utility>
#include <variant>
#include <vector>
@@ -175,14 +176,28 @@
boost::container::flat_map<std::string, std::vector<std::string>>&
eventPathList)
{
+ auto attributePartPos = sensorPathStr.find_last_of('_');
+ if (attributePartPos == std::string::npos)
+ {
+ // There is no '_' in the string, skip it
+ return;
+ }
+ auto attributePart =
+ std::string_view(sensorPathStr).substr(attributePartPos + 1);
+ if (attributePart != "input")
+ {
+ // If the sensor is not xxx_input, skip it
+ return;
+ }
+
+ auto prefixPart = sensorPathStr.substr(0, attributePartPos + 1);
for (const auto& limitMatch : limitEventMatch)
{
const std::vector<std::string>& limitEventAttrs = limitMatch.second;
const std::string& eventName = limitMatch.first;
for (const auto& limitEventAttr : limitEventAttrs)
{
- auto limitEventPath =
- boost::replace_all_copy(sensorPathStr, "input", limitEventAttr);
+ auto limitEventPath = prefixPart + limitEventAttr;
std::ifstream eventFile(limitEventPath);
if (!eventFile.good())
{