Skip to content

Commit

Permalink
changed plugins::loader to be initialized after main #527
Browse files Browse the repository at this point in the history
Because Loader's constructor calls functions in boost::filesystem, and those functions aren't
safe to call before main(), we need to create the global Loader instance in a MONGO_INITIALIZER.
  • Loading branch information
leifwalsh committed Sep 23, 2013
1 parent e24e47c commit a0117ac
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/mongo/db/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ namespace mongo {
srand((unsigned) (curTimeMicros() ^ startupSrandTimer.micros()));

if (!cmdLine.pluginsDir.empty()) {
plugins::loader.setPluginsDir(cmdLine.pluginsDir);
plugins::loader->setPluginsDir(cmdLine.pluginsDir);
}
plugins::loader.autoload(cmdLine.plugins);
plugins::loader->autoload(cmdLine.plugins);

snapshotThread.go();
d.clientCursorMonitor.go();
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ namespace mongo {
log() << "shutdown: going to close databases..." << endl;
dbHolderW().closeDatabases(dbpath);
log() << "shutdown: going to unload all plugins..." << endl;
plugins::loader.shutdown();
plugins::loader->shutdown();
log() << "shutdown: going to shutdown TokuMX..." << endl;
storage::shutdown();
}
Expand Down
6 changes: 3 additions & 3 deletions src/mongo/plugins/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace mongo {
}
checksum = cksumElt.Stringdata();
}
return plugins::loader.load(filename, checksum, errmsg, result);
return plugins::loader->load(filename, checksum, errmsg, result);
}
} loadPluginCommand;

Expand Down Expand Up @@ -105,7 +105,7 @@ namespace mongo {
ListPluginsCommand() : InformationCommand("listPlugins") {}

virtual bool run(const string &db, BSONObj &cmdObj, int options, string &errmsg, BSONObjBuilder &result, bool fromRepl) {
return plugins::loader.list(errmsg, result);
return plugins::loader->list(errmsg, result);
}
} listPluginsCommand;

Expand Down Expand Up @@ -143,7 +143,7 @@ namespace mongo {
errmsg = "unloadPlugin argument must not be empty";
return false;
}
return plugins::loader.unload(name, errmsg, result);
return plugins::loader->unload(name, errmsg, result);
}
} unloadPluginCommand;

Expand Down
14 changes: 12 additions & 2 deletions src/mongo/plugins/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#include <boost/filesystem.hpp>

#include "mongo/base/init.h"
#include "mongo/base/status.h"
#include "mongo/base/string_data.h"
#include "mongo/db/jsobj.h"
#include "mongo/plugins/dl.h"
Expand Down Expand Up @@ -347,11 +349,19 @@ namespace mongo {

fs::path Loader::defaultPluginsDir() {
ProcessInfo p;
fs::path exePath(p.getExePath());
fs::path exePath = p.getExePath();
return exePath.parent_path().parent_path() / "lib64" / "plugins";
}

Loader loader;
Loader *loader;

namespace {
MONGO_INITIALIZER(CreatePluginLoader)(InitializerContext* context) {
// intentionally leaked
loader = new Loader;
return Status::OK();
}
} // namespace

} // namespace plugins

Expand Down
2 changes: 1 addition & 1 deletion src/mongo/plugins/loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace mongo {
void shutdown();
};

extern Loader loader;
extern Loader *loader;

} // namespace plugins

Expand Down
6 changes: 3 additions & 3 deletions src/mongo/s/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ static bool runMongosServer( bool doUpgrade ) {
init();

if (!cmdLine.pluginsDir.empty()) {
plugins::loader.setPluginsDir(cmdLine.pluginsDir);
plugins::loader->setPluginsDir(cmdLine.pluginsDir);
}
plugins::loader.autoload(cmdLine.plugins);
plugins::loader->autoload(cmdLine.plugins);

#if !defined(_WIN32)
CmdLine::launchOk();
Expand Down Expand Up @@ -567,7 +567,7 @@ int main(int argc, char* argv[], char** envp) {

void mongo::exitCleanly( ExitCode code ) {
// TODO: do we need to add anything?
plugins::loader.shutdown();
plugins::loader->shutdown();
mongo::dbexit( code );
}

Expand Down

0 comments on commit a0117ac

Please sign in to comment.