diff options
author | Martijn Otto <git@martijnotto.nl> | 2018-11-20 17:11:06 +0100 |
---|---|---|
committer | Martijn Otto <git@martijnotto.nl> | 2018-11-26 09:37:07 +0100 |
commit | 1132436f972643328e81c3f8929178351a9b96fc (patch) | |
tree | 30d893ec249d67bc3d26637e57d22099ffc022b0 | |
parent | Merge pull request #4781 (diff) | |
download | monero-1132436f972643328e81c3f8929178351a9b96fc.tar.xz |
Only show a single mlock() error, to avoid flooding the log
-rw-r--r-- | contrib/epee/src/mlocker.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/contrib/epee/src/mlocker.cpp b/contrib/epee/src/mlocker.cpp index c3262e8f4..1e831caf1 100644 --- a/contrib/epee/src/mlocker.cpp +++ b/contrib/epee/src/mlocker.cpp @@ -38,6 +38,12 @@ #include "syncobj.h" #include "mlocker.h" +#include <atomic> + +// did an mlock operation previously fail? we only +// want to log an error once and be done with it +static std::atomic<bool> previously_failed{ false }; + static size_t query_page_size() { #if defined HAVE_MLOCK @@ -59,8 +65,8 @@ static void do_lock(void *ptr, size_t len) { #if defined HAVE_MLOCK int ret = mlock(ptr, len); - if (ret < 0) - MERROR("Error locking page at " << ptr << ": " << strerror(errno)); + if (ret < 0 && !previously_failed.exchange(true)) + MERROR("Error locking page at " << ptr << ": " << strerror(errno) << ", subsequent mlock errors will be silenced"); #else #warning Missing do_lock implementation #endif @@ -70,7 +76,10 @@ static void do_unlock(void *ptr, size_t len) { #if defined HAVE_MLOCK int ret = munlock(ptr, len); - if (ret < 0) + // check whether we previously failed, but don't set it, this is just + // to pacify the errors of mlock()ing failed, in which case unlocking + // is also not going to work of course + if (ret < 0 && !previously_failed.load()) MERROR("Error unlocking page at " << ptr << ": " << strerror(errno)); #else #warning Missing implementation of page size detection |