Support reading VERSION_ID without quotes
The VERSION_ID value in /etc/os-release recently had its surrounding
quotation marks removed. Update the code to be able to read values out
of /etc/os-release either with or without quotes, and make it a utility
function so that it can be used in multiple places.
Props to the phosphor-bmc-code-mgmt repo for the elegant implementation.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I348625ba49214ab2977d9e70a4337299bef5ed3a
Change-Id: I9d201954a8116dfda32d096a347e150d93fbfb46
diff --git a/extensions/openpower-pels/data_interface.cpp b/extensions/openpower-pels/data_interface.cpp
index db80757..9db6df8 100644
--- a/extensions/openpower-pels/data_interface.cpp
+++ b/extensions/openpower-pels/data_interface.cpp
@@ -17,6 +17,8 @@
#include "data_interface.hpp"
+#include "util.hpp"
+
#include <fstream>
#include <xyz/openbmc_project/State/OperatingSystem/Status/server.hpp>
@@ -225,35 +227,10 @@
return std::string{};
}
-/**
- * @brief Return a value found in the /etc/os-release file
- *
- * @param[in] key - The key name, like "VERSION"
- *
- * @return std::optional<std::string> - The value
- */
-std::optional<std::string> getOSReleaseValue(const std::string& key)
-{
- std::ifstream versionFile{BMC_VERSION_FILE};
- std::string line;
- std::string keyPattern{key + '='};
-
- while (std::getline(versionFile, line))
- {
- if (line.find(keyPattern) != std::string::npos)
- {
- auto pos = line.find_first_of('"') + 1;
- auto value = line.substr(pos, line.find_last_of('"') - pos);
- return value;
- }
- }
-
- return std::nullopt;
-}
-
void DataInterface::readBMCFWVersion()
{
- _bmcFWVersion = getOSReleaseValue("VERSION").value_or("");
+ _bmcFWVersion =
+ phosphor::logging::util::getOSReleaseValue("VERSION").value_or("");
}
void DataInterface::readServerFWVersion()
@@ -263,7 +240,8 @@
void DataInterface::readBMCFWVersionID()
{
- _bmcFWVersionID = getOSReleaseValue("VERSION_ID").value_or("");
+ _bmcFWVersionID =
+ phosphor::logging::util::getOSReleaseValue("VERSION_ID").value_or("");
}
void DataInterface::readMotherboardCCIN()