Skip to content

Commit 7fd50c3

Browse files
committed
allow libevent logging to be updated during runtime
1 parent 5255aca commit 7fd50c3

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/Makefile.test.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ endif
9797
test_test_bitcoin_SOURCES = $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES)
9898
test_test_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) -I$(builddir)/test/ $(TESTDEFS) $(EVENT_CFLAGS)
9999
test_test_bitcoin_LDADD = $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \
100-
$(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) $(EVENT_LIBS)
100+
$(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS)
101101
test_test_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
102102
if ENABLE_WALLET
103103
test_test_bitcoin_LDADD += $(LIBBITCOIN_WALLET)

src/rpc/misc.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "clientversion.h"
88
#include "init.h"
99
#include "validation.h"
10+
#include "httpserver.h"
1011
#include "net.h"
1112
#include "netbase.h"
1213
#include "rpc/blockchain.h"
@@ -598,6 +599,20 @@ UniValue logging(const JSONRPCRequest& request)
598599
logCategories &= ~getCategoryMask(request.params[1]);
599600
}
600601

602+
// Update libevent logging if BCLog::LIBEVENT has changed.
603+
// If the library version doesn't allow it, UpdateHTTPServerLogging() returns false,
604+
// in which case we should clear the BCLog::LIBEVENT flag.
605+
// Throw an error if the user has explicitly asked to change only the libevent
606+
// flag and it failed.
607+
uint32_t changedLogCategories = originalLogCategories ^ logCategories;
608+
if (changedLogCategories & BCLog::LIBEVENT) {
609+
if (!UpdateHTTPServerLogging(logCategories & BCLog::LIBEVENT)) {
610+
logCategories &= ~BCLog::LIBEVENT;
611+
if (changedLogCategories == BCLog::LIBEVENT) {
612+
throw JSONRPCError(RPC_INVALID_PARAMETER, "libevent logging cannot be updated when using libevent before v2.1.1.");
613+
}
614+
}
615+
}
601616

602617
UniValue result(UniValue::VOBJ);
603618
std::vector<CLogCategoryActive> vLogCatActive = ListActiveLogCategories();

src/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ bool fLogIPs = DEFAULT_LOGIPS;
118118
std::atomic<bool> fReopenDebugLog(false);
119119
CTranslationInterface translationInterface;
120120

121-
/** Log categories bitfield. libevent needs special handling if their flags are changed at runtime. */
121+
/** Log categories bitfield. */
122122
std::atomic<uint32_t> logCategories(0);
123123

124124
/** Init OpenSSL library multithreading support */

0 commit comments

Comments
 (0)