mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-05 13:17:49 +02:00
Merge #15266: memory: Construct globals on first use
77777c5624 log: Construct global logger on first use (MarcoFalke)
Pull request description:
The (de)initialization order is not well defined in C++, so generally it is not safe to use globals as the (de/con)structor of one global could use the (de/con)structor of another global before/after it has been (con/de)structed.
Specifically this fixes:
* `g_logger` might not be initialized on the first use, so do that. (Fixes #15111)
Tree-SHA512: eb9c22f4baf31ebc5b0b9ee6a51d1354bae1f0df186cc0ce818b4483c7b5a7f90268d2b549ee96b4c57f8ef36ab239dc6497f74f3e2ef166038f7437c368297d
This commit is contained in:
@@ -366,9 +366,9 @@ static void EnableOrDisableLogCategories(UniValue cats, bool enable) {
|
||||
|
||||
bool success;
|
||||
if (enable) {
|
||||
success = g_logger->EnableCategory(cat);
|
||||
success = LogInstance().EnableCategory(cat);
|
||||
} else {
|
||||
success = g_logger->DisableCategory(cat);
|
||||
success = LogInstance().DisableCategory(cat);
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
@@ -415,14 +415,14 @@ UniValue logging(const JSONRPCRequest& request)
|
||||
}.ToString());
|
||||
}
|
||||
|
||||
uint32_t original_log_categories = g_logger->GetCategoryMask();
|
||||
uint32_t original_log_categories = LogInstance().GetCategoryMask();
|
||||
if (request.params[0].isArray()) {
|
||||
EnableOrDisableLogCategories(request.params[0], true);
|
||||
}
|
||||
if (request.params[1].isArray()) {
|
||||
EnableOrDisableLogCategories(request.params[1], false);
|
||||
}
|
||||
uint32_t updated_log_categories = g_logger->GetCategoryMask();
|
||||
uint32_t updated_log_categories = LogInstance().GetCategoryMask();
|
||||
uint32_t changed_log_categories = original_log_categories ^ updated_log_categories;
|
||||
|
||||
// Update libevent logging if BCLog::LIBEVENT has changed.
|
||||
@@ -431,8 +431,8 @@ UniValue logging(const JSONRPCRequest& request)
|
||||
// Throw an error if the user has explicitly asked to change only the libevent
|
||||
// flag and it failed.
|
||||
if (changed_log_categories & BCLog::LIBEVENT) {
|
||||
if (!UpdateHTTPServerLogging(g_logger->WillLogCategory(BCLog::LIBEVENT))) {
|
||||
g_logger->DisableCategory(BCLog::LIBEVENT);
|
||||
if (!UpdateHTTPServerLogging(LogInstance().WillLogCategory(BCLog::LIBEVENT))) {
|
||||
LogInstance().DisableCategory(BCLog::LIBEVENT);
|
||||
if (changed_log_categories == BCLog::LIBEVENT) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "libevent logging cannot be updated when using libevent before v2.1.1.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user