From 7a4e0e09320828dc49632622f54d7b2795051f0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chirag=20Dav=C3=A9?= Date: Wed, 4 May 2016 21:40:28 -0700 Subject: [PATCH 1/4] fReopenDebugLog and fRequestShutdown should be type sig_atomic_t This allows access as an atomic variable in the presence of async interrupts. See issue #7433 for more details fixes: #7433 --- src/init.cpp | 2 +- src/util.cpp | 7 ++++--- src/util.h | 10 +++++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 6a9eb6f16..ae6437469 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -111,7 +111,7 @@ CClientUIInterface uiInterface; // Declared but not defined in ui_interface.h // shutdown thing. // -volatile bool fRequestShutdown = false; +volatile sig_atomic_t fRequestShutdown = false; void StartShutdown() { diff --git a/src/util.cpp b/src/util.cpp index b451b65a7..79806d7b6 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -107,9 +107,10 @@ bool fPrintToDebugLog = true; bool fDaemon = false; bool fServer = false; string strMiscWarning; -bool fLogTimestamps = false; -bool fLogIPs = false; -volatile bool fReopenDebugLog = false; +bool fLogTimestamps = DEFAULT_LOGTIMESTAMPS; +bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS; +bool fLogIPs = DEFAULT_LOGIPS; +volatile sig_atomic_t fReopenDebugLog = false; CTranslationInterface translationInterface; /** Init OpenSSL library multithreading support */ diff --git a/src/util.h b/src/util.h index 336e2b1b1..4275d4d07 100644 --- a/src/util.h +++ b/src/util.h @@ -28,6 +28,14 @@ #include #include +#ifndef WIN32 +#include +#endif + +static const bool DEFAULT_LOGTIMEMICROS = false; +static const bool DEFAULT_LOGIPS = false; +static const bool DEFAULT_LOGTIMESTAMPS = true; + /** Signals for translation. */ class CTranslationInterface { @@ -45,7 +53,7 @@ extern bool fServer; extern std::string strMiscWarning; extern bool fLogTimestamps; extern bool fLogIPs; -extern volatile bool fReopenDebugLog; +extern volatile sig_atomic_t fReopenDebugLog; extern CTranslationInterface translationInterface; /** From bf3905fe8f40ccaf3a930b12bf38ff15f53cb3bd Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 27 May 2016 13:30:36 +0200 Subject: [PATCH 2/4] Include signal.h for sig_atomic_t in WIN32 --- src/util.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/util.h b/src/util.h index 4275d4d07..5c62450a7 100644 --- a/src/util.h +++ b/src/util.h @@ -28,9 +28,7 @@ #include #include -#ifndef WIN32 #include -#endif static const bool DEFAULT_LOGTIMEMICROS = false; static const bool DEFAULT_LOGIPS = false; From 3f97a535ee020fc8997c2492737782937445e6b9 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 1 Jun 2016 19:18:06 +0200 Subject: [PATCH 3/4] Revert "Include signal.h for sig_atomic_t in WIN32" This reverts commit 88f14b999cb70f6c556633f2889e698a05305158. --- src/util.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util.h b/src/util.h index 5c62450a7..4275d4d07 100644 --- a/src/util.h +++ b/src/util.h @@ -28,7 +28,9 @@ #include #include +#ifndef WIN32 #include +#endif static const bool DEFAULT_LOGTIMEMICROS = false; static const bool DEFAULT_LOGIPS = false; From bf673640e39eed795f8dd9cfc27c3c867233a99f Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Mon, 30 May 2016 15:39:37 +0200 Subject: [PATCH 4/4] Use std::atomic for fRequestShutdown and fReopenDebugLog --- src/init.cpp | 2 +- src/util.cpp | 2 +- src/util.h | 7 ++----- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index ae6437469..9aea05b7d 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -111,7 +111,7 @@ CClientUIInterface uiInterface; // Declared but not defined in ui_interface.h // shutdown thing. // -volatile sig_atomic_t fRequestShutdown = false; +std::atomic fRequestShutdown(false); void StartShutdown() { diff --git a/src/util.cpp b/src/util.cpp index 79806d7b6..74a714b40 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -110,7 +110,7 @@ string strMiscWarning; bool fLogTimestamps = DEFAULT_LOGTIMESTAMPS; bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS; bool fLogIPs = DEFAULT_LOGIPS; -volatile sig_atomic_t fReopenDebugLog = false; +std::atomic fReopenDebugLog(false); CTranslationInterface translationInterface; /** Init OpenSSL library multithreading support */ diff --git a/src/util.h b/src/util.h index 4275d4d07..9abaa1928 100644 --- a/src/util.h +++ b/src/util.h @@ -18,6 +18,7 @@ #include "tinyformat.h" #include "utiltime.h" +#include #include #include #include @@ -28,10 +29,6 @@ #include #include -#ifndef WIN32 -#include -#endif - static const bool DEFAULT_LOGTIMEMICROS = false; static const bool DEFAULT_LOGIPS = false; static const bool DEFAULT_LOGTIMESTAMPS = true; @@ -53,7 +50,7 @@ extern bool fServer; extern std::string strMiscWarning; extern bool fLogTimestamps; extern bool fLogIPs; -extern volatile sig_atomic_t fReopenDebugLog; +extern std::atomic fReopenDebugLog; extern CTranslationInterface translationInterface; /**