summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/server_status.cpp
diff options
context:
space:
mode:
authorAndrew Morrow <acm@mongodb.com>2017-04-26 13:05:48 -0400
committerAndrew Morrow <acm@mongodb.com>2017-05-01 11:41:38 -0400
commitb779cb0bf72267b8d6cefbb4739c118a720026da (patch)
tree6f9c9e6f5f8bb40f6c0446df61272307eb032112 /src/mongo/db/commands/server_status.cpp
parent3d5c9f8da43874e8d058f323d6f4938efc2a3299 (diff)
downloadmongo-b779cb0bf72267b8d6cefbb4739c118a720026da.tar.gz
SERVER-29012 Enable ASAN strict init order checking and fix revealed issues
Diffstat (limited to 'src/mongo/db/commands/server_status.cpp')
-rw-r--r--src/mongo/db/commands/server_status.cpp30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/mongo/db/commands/server_status.cpp b/src/mongo/db/commands/server_status.cpp
index 6fa1f9d56c7..530e6cf8618 100644
--- a/src/mongo/db/commands/server_status.cpp
+++ b/src/mongo/db/commands/server_status.cpp
@@ -116,7 +116,7 @@ public:
// --- all sections
- for (SectionMap::const_iterator i = _sections->begin(); i != _sections->end(); ++i) {
+ for (SectionMap::const_iterator i = _sections.begin(); i != _sections.end(); ++i) {
ServerStatusSection* section = i->second;
std::vector<Privilege> requiredPrivileges;
@@ -175,10 +175,7 @@ public:
void addSection(ServerStatusSection* section) {
verify(!_runCalled);
- if (_sections == 0) {
- _sections = new SectionMap();
- }
- (*_sections)[section->getSectionName()] = section;
+ _sections[section->getSectionName()] = section;
}
private:
@@ -186,14 +183,29 @@ private:
bool _runCalled;
typedef map<string, ServerStatusSection*> SectionMap;
- static SectionMap* _sections;
-} cmdServerStatus;
+ SectionMap _sections;
+};
+
+namespace {
+
+// This widget ensures that the serverStatus command is registered even if no
+// server status sections are registered.
+const struct CmdServerStatusInstantiator {
+ explicit CmdServerStatusInstantiator() {
+ getInstance();
+ }
+
+ static CmdServerStatus& getInstance() {
+ static CmdServerStatus instance;
+ return instance;
+ }
+} kDoNotMentionThisVariable;
-CmdServerStatus::SectionMap* CmdServerStatus::_sections = 0;
+} // namespace
ServerStatusSection::ServerStatusSection(const string& sectionName) : _sectionName(sectionName) {
- cmdServerStatus.addSection(this);
+ CmdServerStatusInstantiator::getInstance().addSection(this);
}
OpCounterServerStatusSection::OpCounterServerStatusSection(const string& sectionName,