From e85d6b167dcce7ea0c4adee5ea7113f7b6135319 Mon Sep 17 00:00:00 2001 From: "Jason M. Bills" Date: Mon, 29 Jul 2019 17:01:15 -0700 Subject: Don't store LogEntry IDs across requests Because the previous timestamp is stored across Entries requests, a single entry will increment the ID on every refresh since the previous timestamp will always match. This change clears the previous timestamp on the first entry of each request. Tested: Refreshed a single LogEntry many times and confirmed that the ID does not change. Change-Id: I8bf81b6c2eb6ac4037a17008ba54ebfccb42e0dd Signed-off-by: Jason M. Bills --- redfish-core/lib/log_services.hpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp index c74bfa2..94496a1 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -257,11 +257,17 @@ static bool getTopParam(crow::Response &res, const crow::Request &req, return true; } -static bool getUniqueEntryID(sd_journal *journal, std::string &entryID) +static bool getUniqueEntryID(sd_journal *journal, std::string &entryID, + const bool firstEntry = true) { int ret = 0; static uint64_t prevTs = 0; static int index = 0; + if (firstEntry) + { + prevTs = 0; + } + // Get the entry timestamp uint64_t curTs = 0; ret = sd_journal_get_realtime_usec(journal, &curTs); @@ -292,10 +298,16 @@ static bool getUniqueEntryID(sd_journal *journal, std::string &entryID) return true; } -static bool getUniqueEntryID(const std::string &logEntry, std::string &entryID) +static bool getUniqueEntryID(const std::string &logEntry, std::string &entryID, + const bool firstEntry = true) { static uint64_t prevTs = 0; static int index = 0; + if (firstEntry) + { + prevTs = 0; + } + // Get the entry timestamp uint64_t curTs = 0; std::tm timeStruct = {}; @@ -713,6 +725,8 @@ class JournalEventLogEntryCollection : public Node continue; } + // Reset the unique ID on the first entry + bool firstEntry = true; while (std::getline(logStream, logEntry)) { entryCount++; @@ -724,11 +738,16 @@ class JournalEventLogEntryCollection : public Node } std::string idStr; - if (!getUniqueEntryID(logEntry, idStr)) + if (!getUniqueEntryID(logEntry, idStr, firstEntry)) { continue; } + if (firstEntry) + { + firstEntry = false; + } + logEntryArray.push_back({}); nlohmann::json &bmcLogEntry = logEntryArray.back(); if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 0) @@ -1250,6 +1269,8 @@ class BMCJournalLogEntryCollection : public Node journalTmp, sd_journal_close); journalTmp = nullptr; uint64_t entryCount = 0; + // Reset the unique ID on the first entry + bool firstEntry = true; SD_JOURNAL_FOREACH(journal.get()) { entryCount++; @@ -1261,11 +1282,16 @@ class BMCJournalLogEntryCollection : public Node } std::string idStr; - if (!getUniqueEntryID(journal.get(), idStr)) + if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) { continue; } + if (firstEntry) + { + firstEntry = false; + } + logEntryArray.push_back({}); nlohmann::json &bmcJournalLogEntry = logEntryArray.back(); if (fillBMCJournalLogEntryJson(idStr, journal.get(), -- cgit v1.2.3