diff options
author | Konrad Lipinski <k.lipinski2@samsung.com> | 2022-08-02 09:35:50 +0200 |
---|---|---|
committer | Konrad Lipinski <k.lipinski2@samsung.com> | 2022-08-02 12:54:56 +0200 |
commit | 12ae9c73bcc53de2215b64e24a6235dc28580a6c (patch) | |
tree | 54847ba61522291fc5ab3cba6752361b2abe3a1c | |
parent | b0bbeaac64629e42e71a1570129cf3e8afd3fb64 (diff) | |
download | security-manager-12ae9c73bcc53de2215b64e24a6235dc28580a6c.tar.gz security-manager-12ae9c73bcc53de2215b64e24a6235dc28580a6c.tar.bz2 security-manager-12ae9c73bcc53de2215b64e24a6235dc28580a6c.zip |
Switch to CLOCK_MONOTONIC_COARSE
All uses of clock_gettime() are fine with coarse granularity. Renamed
monotonicNow() to monotonicCoarseNow() to reflect that.
Change-Id: Id60e79ca28a888ad98907184b7c11dd9d0b4aeee
-rw-r--r-- | src/common/include/utils.h | 2 | ||||
-rw-r--r-- | src/common/utils.cpp | 6 | ||||
-rw-r--r-- | src/server/main/socket-manager.cpp | 8 | ||||
-rw-r--r-- | test/test_misc.cpp | 2 |
4 files changed, 9 insertions, 9 deletions
diff --git a/src/common/include/utils.h b/src/common/include/utils.h index b4998880..8ee30be0 100644 --- a/src/common/include/utils.h +++ b/src/common/include/utils.h @@ -50,7 +50,7 @@ namespace SecurityManager { */ int try_catch(const std::function<int()>& func); -time_t monotonicNow(); +time_t monotonicCoarseNow(); // Used for measuring function/method/scope execution time class ScopedTimeStamper { diff --git a/src/common/utils.cpp b/src/common/utils.cpp index f30f8a20..071919f8 100644 --- a/src/common/utils.cpp +++ b/src/common/utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2019-2022 Samsung Electronics Co., Ltd. All rights reserved. * * This file is licensed under the terms of MIT License or the Apache License * Version 2.0 of your choice. See the LICENSE.MIT file for MIT license details. @@ -71,9 +71,9 @@ int try_catch(const std::function<int()>& func) return SECURITY_MANAGER_ERROR_UNKNOWN; } -time_t monotonicNow() { +time_t monotonicCoarseNow() { struct timespec now; - if (clock_gettime(CLOCK_MONOTONIC_RAW, &now) == -1) { + if (clock_gettime(CLOCK_MONOTONIC_COARSE, &now)) { int err = errno; LogError("Can't access monotonic clock, error: " << GetErrnoString(err)); return 0; diff --git a/src/server/main/socket-manager.cpp b/src/server/main/socket-manager.cpp index c7623412..97b50d4e 100644 --- a/src/server/main/socket-manager.cpp +++ b/src/server/main/socket-manager.cpp @@ -75,7 +75,7 @@ void SocketManager::CreateDefaultReadSocketDescription(int sock) auto &desc = m_socketDescriptionVector[sock]; desc.isOpen = true; - desc.timeout = monotonicNow() + SOCKET_TIMEOUT; + desc.timeout = monotonicCoarseNow() + SOCKET_TIMEOUT; desc.buffer.InitForInput(); if (false == desc.isTimeout) { @@ -172,7 +172,7 @@ bool SocketManager::GotSigTerm() const { void SocketManager::ReadyForRead(int sock) { auto &desc = m_socketDescriptionVector[sock]; auto &buffer = desc.buffer; - desc.timeout = monotonicNow() + SOCKET_TIMEOUT; + desc.timeout = monotonicCoarseNow() + SOCKET_TIMEOUT; ssize_t size = read(sock, buffer.Ptr(), buffer.InputSize()); @@ -242,7 +242,7 @@ void SocketManager::ReadyForWrite(int sock) { return; // We do not want to propagate error to next layer } - desc.timeout = monotonicNow() + SOCKET_TIMEOUT; + desc.timeout = monotonicCoarseNow() + SOCKET_TIMEOUT; if (buffer.OutputDone(result)) CloseSocket(sock); } @@ -285,7 +285,7 @@ void SocketManager::MainLoop() { LogDebug("No usable timeout found."); ptrTimeout = NULL; // select will wait without timeout } else { - time_t currentTime = monotonicNow(); + time_t currentTime = monotonicCoarseNow(); auto &pqTimeout = m_timeoutQueue.top(); // 0 means that select won't block and socket will be closed ;-) diff --git a/test/test_misc.cpp b/test/test_misc.cpp index 80716a0f..ee99bbcb 100644 --- a/test/test_misc.cpp +++ b/test/test_misc.cpp @@ -118,7 +118,7 @@ POSITIVE_TEST_CASE(T287_groups_loading) POSITIVE_TEST_CASE(T288_monotonic_clock) { time_t t; - BOOST_REQUIRE_NO_THROW(t = monotonicNow()); + BOOST_REQUIRE_NO_THROW(t = monotonicCoarseNow()); BOOST_REQUIRE_MESSAGE(t > 0, "Invalid monotonic time value"); } |