From bb4e71ed2ebdee1ac5e4b3eee390060e19fea0d8 Mon Sep 17 00:00:00 2001 From: John Spray Date: Thu, 12 Oct 2017 13:14:02 -0400 Subject: [PATCH] mgr: fix thread naming Was passing a reference to a local stringstream into Thread::create, not realising that it was taking a char* reference instead of a copy. Result was garbage (or usually, all threads having the name of the last one created) Signed-off-by: John Spray --- src/mgr/ActivePyModules.cc | 7 ++++--- src/mgr/StandbyPyModules.cc | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/mgr/ActivePyModules.cc b/src/mgr/ActivePyModules.cc index e1cde4fd7d31d..072f10d1c7955 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -336,10 +336,11 @@ int ActivePyModules::start_one(std::string const &module_name, if (r != 0) { return r; } else { - std::ostringstream thread_name; - thread_name << "mgr." << module_name; dout(4) << "Starting thread for " << module_name << dendl; - modules[module_name]->thread.create(thread_name.str().c_str()); + // Giving Thread the module's module_name member as its + // char* thread name: thread must not outlive module class lifetime. + modules[module_name]->thread.create( + modules[module_name]->get_name().c_str()); return 0; } diff --git a/src/mgr/StandbyPyModules.cc b/src/mgr/StandbyPyModules.cc index 3992553bd4408..2b442d5ef9d29 100644 --- a/src/mgr/StandbyPyModules.cc +++ b/src/mgr/StandbyPyModules.cc @@ -97,10 +97,11 @@ int StandbyPyModules::start_one(std::string const &module_name, modules.erase(module_name); return r; } else { - std::ostringstream thread_name; - thread_name << "mgr." << module_name; dout(4) << "Starting thread for " << module_name << dendl; - modules[module_name]->thread.create(thread_name.str().c_str()); + // Giving Thread the module's module_name member as its + // char* thread name: thread must not outlive module class lifetime. + modules[module_name]->thread.create( + modules[module_name]->get_name().c_str()); return 0; } } -- 2.39.5