clang-tidy: Enable bugprone-unchecked-optional-access
Enable bugprone-unchecked-optional-access to detect the case that it
accesses std::optional without checking empty.
See https://gerrit.openbmc.org/c/openbmc/docs/+/78034 for details.
This commit also fixes quite a few issues reported by clang-tidy:
* Add necessary includes in the hpp files;
* Move the template function `selAddSystemRecord()` into hpp;
* Fix the uncheck access of `expireAction`.
Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: I4ad3cc07510a03965a2b4ae9c08fe452433ccdab
diff --git a/src/sel_logger.cpp b/src/sel_logger.cpp
index 493b443..5e7e02a 100644
--- a/src/sel_logger.cpp
+++ b/src/sel_logger.cpp
@@ -349,7 +349,7 @@
#endif
#endif
-static void toHexStr(const std::vector<uint8_t>& data, std::string& hexStr)
+void toHexStr(const std::vector<uint8_t>& data, std::string& hexStr)
{
std::stringstream stream;
stream << std::hex << std::uppercase << std::setfill('0');
@@ -360,58 +360,6 @@
hexStr = stream.str();
}
-template <typename... T>
-static uint16_t selAddSystemRecord(
- [[maybe_unused]] std::shared_ptr<sdbusplus::asio::connection> conn,
- [[maybe_unused]] const std::string& message, const std::string& path,
- const std::vector<uint8_t>& selData, const bool& assert,
- const uint16_t& genId, [[maybe_unused]] T&&... metadata)
-{
- // Only 3 bytes of SEL event data are allowed in a system record
- if (selData.size() > selEvtDataMaxSize)
- {
- throw std::invalid_argument("Event data too large");
- }
- std::string selDataStr;
- toHexStr(selData, selDataStr);
-
-#ifdef SEL_LOGGER_SEND_TO_LOGGING_SERVICE
- sdbusplus::message_t AddToLog = conn->new_method_call(
- "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
- "xyz.openbmc_project.Logging.Create", "Create");
-
- std::string journalMsg(
- message + " from " + path + ": " +
- " RecordType=" + std::to_string(selSystemType) +
- ", GeneratorID=" + std::to_string(genId) +
- ", EventDir=" + std::to_string(assert) + ", EventData=" + selDataStr);
-
- AddToLog.append(
- journalMsg, "xyz.openbmc_project.Logging.Entry.Level.Informational",
- std::map<std::string, std::string>(
- {{"SENSOR_PATH", path},
- {"GENERATOR_ID", std::to_string(genId)},
- {"RECORD_TYPE", std::to_string(selSystemType)},
- {"EVENT_DIR", std::to_string(assert)},
- {"SENSOR_DATA", selDataStr}}));
- conn->call(AddToLog);
- return 0;
-#else
- unsigned int recordId = getNewRecordId();
- if (recordId < selInvalidRecID)
- {
- sd_journal_send(
- "MESSAGE=%s", message.c_str(), "PRIORITY=%i", selPriority,
- "MESSAGE_ID=%s", selMessageId, "IPMI_SEL_RECORD_ID=%d", recordId,
- "IPMI_SEL_RECORD_TYPE=%x", selSystemType,
- "IPMI_SEL_GENERATOR_ID=%x", genId, "IPMI_SEL_SENSOR_PATH=%s",
- path.c_str(), "IPMI_SEL_EVENT_DIR=%x", assert, "IPMI_SEL_DATA=%s",
- selDataStr.c_str(), std::forward<T>(metadata)..., NULL);
- }
- return recordId;
-#endif
-}
-
static uint16_t selAddOemRecord(
[[maybe_unused]] std::shared_ptr<sdbusplus::asio::connection> conn,
[[maybe_unused]] const std::string& message,