summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorADAM David Alan Martin <adam.martin@10gen.com>2017-01-19 16:28:55 -0500
committerADAM David Alan Martin <adam.martin@10gen.com>2017-01-19 16:28:55 -0500
commit0d89f9f90e4f6a7ab00ce406b459d450b63e6ef3 (patch)
tree226384d993e91408ffd386a3f6fa4db870a5d0be /src
parent6add2c82bacecd5f54613ebf4be1553f3b046cbc (diff)
downloadmongo-0d89f9f90e4f6a7ab00ce406b459d450b63e6ef3.tar.gz
SERVER-27710 Move SNMP init hook out of db.cpp.
The `src/mongo/db.cpp` file is compiled into the main server program, and causes broken-dependency issues in linking the enterprise modules. By moving this symbol to another file, we can better express this dependency. Further, this change lays the groundwork to switch from from a pointer to function to a `std::function< void () >` object.
Diffstat (limited to 'src')
-rw-r--r--src/mongo/SConscript1
-rw-r--r--src/mongo/db/SConscript8
-rw-r--r--src/mongo/db/db.cpp8
-rw-r--r--src/mongo/db/db.h3
-rw-r--r--src/mongo/db/initialize_snmp.cpp51
-rw-r--r--src/mongo/db/initialize_snmp.h43
6 files changed, 105 insertions, 9 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript
index ccd0bbf341c..401ff9d684b 100644
--- a/src/mongo/SConscript
+++ b/src/mongo/SConscript
@@ -280,6 +280,7 @@ mongodLibDeps = [
'db/dbdirectclient',
'db/ftdc/ftdc_mongod',
'db/index_d',
+ 'db/initialize_snmp',
'db/mongod_options',
'db/mongodandmongos',
'db/op_observer_d',
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index 4e739fcf51b..969eacd6d0b 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -61,6 +61,14 @@ env.Library(
]
)
+env.Library(
+ target='initialize_snmp',
+ source= [
+ 'initialize_snmp.cpp',
+ ],
+ LIBDEPS=[],
+)
+
env.CppUnitTest(
target= 'field_ref_test',
source= 'field_ref_test.cpp',
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp
index d57bd570700..cbcf906326e 100644
--- a/src/mongo/db/db.cpp
+++ b/src/mongo/db/db.cpp
@@ -158,8 +158,6 @@ using std::vector;
using logger::LogComponent;
-void (*snmpInit)() = NULL;
-
extern int diagLogging;
namespace {
@@ -558,11 +556,7 @@ ExitCode _initAndListen(int listenPort) {
uassert(12590, ss.str().c_str(), boost::filesystem::exists(storageGlobalParams.repairpath));
}
- // TODO: This should go into a MONGO_INITIALIZER once we have figured out the correct
- // dependencies.
- if (snmpInit) {
- snmpInit();
- }
+ initializeSNMP();
if (!storageGlobalParams.readOnly) {
boost::filesystem::remove_all(storageGlobalParams.dbpath + "/_tmp/");
diff --git a/src/mongo/db/db.h b/src/mongo/db/db.h
index f5ca27cd748..5b0c4e33764 100644
--- a/src/mongo/db/db.h
+++ b/src/mongo/db/db.h
@@ -33,6 +33,7 @@
#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/client.h"
#include "mongo/db/curop.h"
+#include "mongo/db/initialize_snmp.h"
#include "mongo/util/net/message.h"
namespace mongo {
@@ -41,6 +42,4 @@ namespace repl {
class ReplSettings;
} // namespace repl
-extern void (*snmpInit)();
-
} // namespace mongo
diff --git a/src/mongo/db/initialize_snmp.cpp b/src/mongo/db/initialize_snmp.cpp
new file mode 100644
index 00000000000..8610d863280
--- /dev/null
+++ b/src/mongo/db/initialize_snmp.cpp
@@ -0,0 +1,51 @@
+/**
+ * Copyright (C) 2017 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#include "mongo/db/initialize_snmp.h"
+
+namespace mongo {
+// Exposed in `src/mongo/db/db.h`, for legacy reasons.
+void (*snmpInit)() = nullptr;
+
+namespace {
+std::function<void()> snmpInitializer = [] {
+ if (snmpInit) {
+ snmpInit();
+ }
+};
+}
+}
+
+void mongo::registerSNMPInitializer(stdx::function<void()> init) {
+ // TODO: Check for reinitialization
+ snmpInitializer = std::move(init);
+}
+
+void mongo::initializeSNMP() {
+ return snmpInitializer();
+}
diff --git a/src/mongo/db/initialize_snmp.h b/src/mongo/db/initialize_snmp.h
new file mode 100644
index 00000000000..9626cd2c56c
--- /dev/null
+++ b/src/mongo/db/initialize_snmp.h
@@ -0,0 +1,43 @@
+/**
+ * Copyright (C) 2017 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+
+#pragma once
+
+#include "mongo/stdx/functional.h"
+
+namespace mongo {
+
+void registerSNMPInitializer(stdx::function<void()> init);
+
+void initializeSNMP();
+
+// Deprecated -- will be removed.
+extern void (*snmpInit)();
+
+} // namespace mongo