summaryrefslogtreecommitdiff
path: root/src/mongo/base
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2013-05-23 10:44:44 -0400
committerEric Milkie <milkie@10gen.com>2013-05-23 10:44:44 -0400
commitc3c8ec43d247635a2c6c418ce7f540b2c34390ea (patch)
treea294ba622b2f7c78b3aa0877a445623b20b16bc5 /src/mongo/base
parentb7c80ec25658288217947e3d4aaf1e27826bb578 (diff)
downloadmongo-c3c8ec43d247635a2c6c418ce7f540b2c34390ea.tar.gz
SERVER-9768 create non-dying entry point for running initializers, for use by C++ driver users
Diffstat (limited to 'src/mongo/base')
-rw-r--r--src/mongo/base/initializer.cpp26
-rw-r--r--src/mongo/base/initializer.h5
2 files changed, 13 insertions, 18 deletions
diff --git a/src/mongo/base/initializer.cpp b/src/mongo/base/initializer.cpp
index 42075d59b15..940d7e5df0f 100644
--- a/src/mongo/base/initializer.cpp
+++ b/src/mongo/base/initializer.cpp
@@ -55,21 +55,10 @@ namespace mongo {
Status runGlobalInitializers(const InitializerContext::ArgumentVector& args,
const InitializerContext::EnvironmentMap& env) {
-
return getGlobalInitializer().execute(args, env);
}
- void runGlobalInitializersOrDie(const InitializerContext::ArgumentVector& args,
- const InitializerContext::EnvironmentMap& env) {
-
- Status status = runGlobalInitializers(args, env);
- if (Status::OK() != status) {
- std::cerr << "Failed global initialization: " << status << std::endl;
- ::_exit(1);
- }
- }
-
- void runGlobalInitializersOrDie(int argc, const char* const* argv, const char* const* envp) {
+ Status runGlobalInitializers(int argc, const char* const* argv, const char* const* envp) {
InitializerContext::ArgumentVector args(argc);
std::copy(argv, argv + argc, args.begin());
@@ -79,14 +68,21 @@ namespace mongo {
for(; *envp; ++envp) {
const char* firstEqualSign = strchr(*envp, '=');
if (!firstEqualSign) {
- std::cerr << "Failed global initialization: malformed environment block\n";
- ::_exit(1);
+ return Status(ErrorCodes::BadValue, "malformed environment block");
}
env[std::string(*envp, firstEqualSign)] = std::string(firstEqualSign + 1);
}
}
- runGlobalInitializersOrDie(args, env);
+ return runGlobalInitializers(args, env);
+ }
+
+ void runGlobalInitializersOrDie(int argc, const char* const* argv, const char* const* envp) {
+ Status status = runGlobalInitializers(argc, argv, envp);
+ if (!status.isOK()) {
+ std::cerr << "Failed global initialization: " << status << std::endl;
+ ::_exit(1);
+ }
}
} // namespace mongo
diff --git a/src/mongo/base/initializer.h b/src/mongo/base/initializer.h
index e54560eb72b..728672fc5b5 100644
--- a/src/mongo/base/initializer.h
+++ b/src/mongo/base/initializer.h
@@ -80,13 +80,12 @@ namespace mongo {
Status runGlobalInitializers(const InitializerContext::ArgumentVector& args,
const InitializerContext::EnvironmentMap& env);
+ Status runGlobalInitializers(int argc, const char* const* argv, const char* const* envp);
+
/**
* Same as runGlobalInitializers(), except prints a brief message to std::cerr
* and terminates the process on failure.
*/
- void runGlobalInitializersOrDie(const InitializerContext::ArgumentVector& args,
- const InitializerContext::EnvironmentMap& env);
-
void runGlobalInitializersOrDie(int argc, const char* const* argv, const char* const* envp);
} // namespace mongo