diff options
author | Ed Tanous <ed@tanous.net> | 2024-03-07 21:13:14 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2024-03-19 01:31:07 +0300 |
commit | c51afd54a55d5c8d6cb6e9583e209788f7996fe3 (patch) | |
tree | 6dc363cb66c1a1205904220b8a486acb86b48e1c /redfish-core/src/utils/time_utils.cpp | |
parent | 53b00f5d985d055bddd175f7192128ae7c3286a2 (diff) | |
download | bmcweb-c51afd54a55d5c8d6cb6e9583e209788f7996fe3.tar.xz |
Call systemd SetTime directly
Internally inside phosphor-time-manager, the elapsed(uint64) dbus call
just forwards the request directly to systemd after static casting to
int64_t (signed).
bmcweb should just call systemd directly, for several reasons.
phosphor-timesyncd might block on other calls, given it's a single
threaded blocking design, due to bugs like #264. Calling systemd
directly means that calls that don't require phosphor networkd won't be
blocked.
Calling systemd directly allows bmcweb to drop some code that parses a
date as int64_t, then converts it to uint64_t to fulfill the phosphor
datetime interface. We can now keep int64_t all the way through.
Calling systemd directly allows bmcweb to give a more specific error
code in the case there NTP is enabled, registering a
PropertyValueConflict error, instead of a 500 InternalError.
Tested:
Patching DateTime property with NTP enabled returns 400,
PropertyValueConflict
```
curl -vvvv -k --user "root:0penBmc" -H "Content-Type: application/json" -X PATCH -d '{"DateTime":"2020-12-15T15:40:52+00:00"}' https://192.168.7.2/redfish/v1/Managers/bmc
```
Disabling NTP using the following command:
```
curl -vvvv -k --user "root:0penBmc" -H "Content-Type: application/json" -X PATCH -d '{"NTP":{"ProtocolEnabled":false}}' https://192.168.7.2/redfish/v1/Managers/bmc/NetworkProtocol
```
Allows the prior command to succeed.
[1] https://github.com/openbmc/phosphor-time-manager/blob/5ce9ac0e56440312997b25771507585905e8b360/bmc_epoch.cpp#L126
Change-Id: I6fbb6f63e17de8ab847ca5ed4eadc2bd313586d2
Signed-off-by: Ed Tanous <ed@tanous.net>
Diffstat (limited to 'redfish-core/src/utils/time_utils.cpp')
-rw-r--r-- | redfish-core/src/utils/time_utils.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/redfish-core/src/utils/time_utils.cpp b/redfish-core/src/utils/time_utils.cpp index f427ba64c4..3aa3e79b54 100644 --- a/redfish-core/src/utils/time_utils.cpp +++ b/redfish-core/src/utils/time_utils.cpp @@ -12,13 +12,13 @@ namespace redfish::time_utils { -using usSinceEpoch = std::chrono::duration<uint64_t, std::micro>; + std::optional<usSinceEpoch> dateStringToEpoch(std::string_view datetime) { for (const char* format : std::to_array({"%FT%T%Ez", "%FT%TZ", "%FT%T"})) { // Parse using signed so we can detect negative dates - std::chrono::sys_time<std::chrono::duration<int64_t, std::micro>> date; + std::chrono::sys_time<usSinceEpoch> date; std::istringstream iss(std::string{datetime}); #if __cpp_lib_chrono >= 201907L namespace chrono_from_stream = std::chrono; @@ -36,7 +36,7 @@ std::optional<usSinceEpoch> dateStringToEpoch(std::string_view datetime) // More information left at end of string. continue; } - return usSinceEpoch{date.time_since_epoch().count()}; + return date.time_since_epoch(); } } return std::nullopt; |