Skip to content

Commit

Permalink
Don't rename main thread at process level
Browse files Browse the repository at this point in the history
Set only the internal name.

Fixes #17036 for both `bitcoind` and `bitcoin-qt`.
  • Loading branch information
laanwj authored and dagurval committed Oct 28, 2020
1 parent 7b2dfa8 commit 10cead4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/bitcoind.cpp
Expand Up @@ -73,7 +73,7 @@ static bool AppInit(int argc, char *argv[]) {

bool fRet = false;

util::ThreadRename("init");
util::ThreadSetInternalName("init");

//
// Parameters
Expand Down
2 changes: 1 addition & 1 deletion src/qt/bitcoin.cpp
Expand Up @@ -518,7 +518,7 @@ int GuiMain(int argc, char *argv[]) {
std::tie(argc, argv) = winArgs.get();
#endif
SetupEnvironment();
util::ThreadRename("main");
util::ThreadSetInternalName("main");

std::unique_ptr<interfaces::Node> node = interfaces::MakeNode();

Expand Down
5 changes: 5 additions & 0 deletions src/util/threadnames.cpp
Expand Up @@ -48,3 +48,8 @@ void util::ThreadRename(std::string&& name)
SetThreadName(("b-" + name).c_str());
SetInternalName(std::move(name));
}

void util::ThreadSetInternalName(std::string&& name)
{
SetInternalName(std::move(name));
}
5 changes: 5 additions & 0 deletions src/util/threadnames.h
Expand Up @@ -10,8 +10,13 @@
namespace util {
//! Rename a thread both in terms of an internal (in-memory) name as well
//! as its system thread name.
//! @note Do not call this for the main thread, as this will interfere with
//! UNIX utilities such as top and killall. Use ThreadSetInternalName instead.
void ThreadRename(std::string&&);

//! Set the internal (in-memory) name of the current thread only.
void ThreadSetInternalName(std::string&&);

//! Get the thread's internal (in-memory) name; used e.g. for identification in
//! logging.
const std::string& ThreadGetInternalName();
Expand Down

0 comments on commit 10cead4

Please sign in to comment.