diff options
author | Ed Tanous <edtanous@google.com> | 2022-01-26 23:19:54 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-02-04 01:11:33 +0300 |
commit | c419c759177f7d42af4848bc9d16bca3c1644387 (patch) | |
tree | 92273298d3b5b564b90d5ea646f98c1a30b6136b /redfish-core/lib/log_services.hpp | |
parent | 67df073b1f0950fdeafc6d30240d360bd162d0f8 (diff) | |
download | bmcweb-c419c759177f7d42af4848bc9d16bca3c1644387.tar.xz |
Remove getTimestamp
The aforementioned function is only used in the log services, and is
used incorrectly in that context. This commit replaces it with the
correct (and unit tested) getDateTimeUintMs, which is what we should be
using for dbus->time conversions in all cases, to avoid time_t
overflows when static casting.
Tested:
Before
"Created": "2022-01-31T19:39:58+00:00",
"Modified": "2022-01-31T19:39:58+00:00",
With change:
"Created": "2022-01-31T19:39:58.101000+00:00",
"Modified": "2022-01-31T19:39:58.101000+00:00",
The Redfish validator is okay with this
*** /redfish/v1/Systems/system/LogServices/EventLog/Entries/1000
Type (LogEntry.v1_8_0.LogEntry), GET SUCCESS (time: 0)
PASS
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ie8a2243230ee080d9e8785ae918fad1b1b6ab145
Diffstat (limited to 'redfish-core/lib/log_services.hpp')
-rw-r--r-- | redfish-core/lib/log_services.hpp | 59 |
1 files changed, 18 insertions, 41 deletions
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp index 43be44b4a7..e20a2baacf 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -1428,8 +1428,8 @@ inline void requestRoutesDBusEventLogEntryCollection(App& app) for (auto& objectPath : resp) { const uint32_t* id = nullptr; - std::time_t timestamp{}; - std::time_t updateTimestamp{}; + const uint64_t* timestamp = nullptr; + const uint64_t* updateTimestamp = nullptr; const std::string* severity = nullptr; const std::string* message = nullptr; const std::string* filePath = nullptr; @@ -1448,28 +1448,14 @@ inline void requestRoutesDBusEventLogEntryCollection(App& app) } else if (propertyMap.first == "Timestamp") { - const uint64_t* millisTimeStamp = - std::get_if<uint64_t>( - &propertyMap.second); - if (millisTimeStamp != nullptr) - { - timestamp = - crow::utility::getTimestamp( - *millisTimeStamp); - } + timestamp = std::get_if<uint64_t>( + &propertyMap.second); } else if (propertyMap.first == "UpdateTimestamp") { - const uint64_t* millisTimeStamp = - std::get_if<uint64_t>( - &propertyMap.second); - if (millisTimeStamp != nullptr) - { - updateTimestamp = - crow::utility::getTimestamp( - *millisTimeStamp); - } + updateTimestamp = std::get_if<uint64_t>( + &propertyMap.second); } else if (propertyMap.first == "Severity") { @@ -1519,7 +1505,8 @@ inline void requestRoutesDBusEventLogEntryCollection(App& app) // xyz.openbmc_project.Logging.Entry interface, ignore // and continue. if (id == nullptr || message == nullptr || - severity == nullptr) + severity == nullptr || timestamp == nullptr || + updateTimestamp == nullptr) { continue; } @@ -1537,9 +1524,9 @@ inline void requestRoutesDBusEventLogEntryCollection(App& app) thisEntry["Severity"] = translateSeverityDbusToRedfish(*severity); thisEntry["Created"] = - crow::utility::getDateTimeStdtime(timestamp); + crow::utility::getDateTimeUintMs(*timestamp); thisEntry["Modified"] = - crow::utility::getDateTimeStdtime(updateTimestamp); + crow::utility::getDateTimeUintMs(*updateTimestamp); if (filePath != nullptr) { thisEntry["AdditionalDataURI"] = @@ -1594,8 +1581,8 @@ inline void requestRoutesDBusEventLogEntry(App& app) return; } const uint32_t* id = nullptr; - std::time_t timestamp{}; - std::time_t updateTimestamp{}; + const uint64_t* timestamp = nullptr; + const uint64_t* updateTimestamp = nullptr; const std::string* severity = nullptr; const std::string* message = nullptr; const std::string* filePath = nullptr; @@ -1609,24 +1596,13 @@ inline void requestRoutesDBusEventLogEntry(App& app) } else if (propertyMap.first == "Timestamp") { - const uint64_t* millisTimeStamp = + timestamp = std::get_if<uint64_t>(&propertyMap.second); - if (millisTimeStamp != nullptr) - { - timestamp = crow::utility::getTimestamp( - *millisTimeStamp); - } } else if (propertyMap.first == "UpdateTimestamp") { - const uint64_t* millisTimeStamp = + updateTimestamp = std::get_if<uint64_t>(&propertyMap.second); - if (millisTimeStamp != nullptr) - { - updateTimestamp = - crow::utility::getTimestamp( - *millisTimeStamp); - } } else if (propertyMap.first == "Severity") { @@ -1656,7 +1632,8 @@ inline void requestRoutesDBusEventLogEntry(App& app) } } if (id == nullptr || message == nullptr || - severity == nullptr) + severity == nullptr || timestamp == nullptr || + updateTimestamp == nullptr) { messages::internalError(asyncResp->res); return; @@ -1675,9 +1652,9 @@ inline void requestRoutesDBusEventLogEntry(App& app) asyncResp->res.jsonValue["Severity"] = translateSeverityDbusToRedfish(*severity); asyncResp->res.jsonValue["Created"] = - crow::utility::getDateTimeStdtime(timestamp); + crow::utility::getDateTimeUintMs(*timestamp); asyncResp->res.jsonValue["Modified"] = - crow::utility::getDateTimeStdtime(updateTimestamp); + crow::utility::getDateTimeUintMs(*updateTimestamp); if (filePath != nullptr) { asyncResp->res.jsonValue["AdditionalDataURI"] = |