summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2008-09-12 11:26:51 -0400
committerDwight <dmerriman@gmail.com>2008-09-12 11:26:51 -0400
commit18e7e1fa40da60fe6670123c86e6eedc8bdc1dfb (patch)
tree94db452ff18188325cdbe27d9ee79399ef564a91
parente9370576adf9d8e023988dacb37a6d291b0d14f4 (diff)
downloadmongo-18e7e1fa40da60fe6670123c86e6eedc8bdc1dfb.tar.gz
fix assumed initialization order of globals
-rw-r--r--db/cloner.cpp14
-rw-r--r--db/commands.cpp18
-rw-r--r--db/commands.h7
3 files changed, 24 insertions, 15 deletions
diff --git a/db/cloner.cpp b/db/cloner.cpp
index e06d4d8276d..9ce0eb7d0e3 100644
--- a/db/cloner.cpp
+++ b/db/cloner.cpp
@@ -22,6 +22,7 @@
#include "../util/builder.h"
#include "jsobj.h"
#include "query.h"
+#include "commands.h"
extern int port;
bool userCreateNS(const char *ns, JSObj& j, string& err);
@@ -87,3 +88,16 @@ bool cloneFrom(const char *masterHost, string& errmsg)
Cloner c;
return c.go(masterHost, errmsg);
}
+
+class CmdClone : public Command {
+public:
+ CmdClone() : Command("clone") { }
+
+ virtual bool run(const char *ns, JSObj& cmdObj, string& errmsg, JSObjBuilder& result) {
+ string from = cmdObj.getStringField("clone");
+ if( from.empty() )
+ return false;
+ return cloneFrom(from.c_str(), errmsg);
+ }
+} cmdclone;
+
diff --git a/db/commands.cpp b/db/commands.cpp
index 049b14e1dec..95ee8117763 100644
--- a/db/commands.cpp
+++ b/db/commands.cpp
@@ -40,7 +40,14 @@ int runCount(const char *ns, JSObj& cmd, string& err);
const int edebug=0;
-map<string,Command*> Command::commands;
+static map<string,Command*> *commands;
+
+Command::Command(const char *_name) : name(_name) {
+ // register ourself.
+ if( commands == 0 )
+ commands = new map<string,Command*>;
+ (*commands)[name] = this;
+}
bool dbEval(JSObj& cmd, JSObjBuilder& result) {
Element e = cmd.firstElement();
@@ -300,7 +307,7 @@ bool _runCommands(const char *ns, JSObj& jsobj, stringstream& ss, BufBuilder &b,
/* check for properly registered command objects. Note that all the commands below should be
migrated over to the command object format.
*/
- else if( (i = Command::commands.find(e.fieldName())) != Command::commands.end() ) {
+ else if( (i = commands->find(e.fieldName())) != commands->end() ) {
valid = true;
string errmsg;
Command *c = i->second;
@@ -370,13 +377,6 @@ bool _runCommands(const char *ns, JSObj& jsobj, stringstream& ss, BufBuilder &b,
}
anObjBuilder.append("n", (double) nn);
}
- else if( strcmp( e.fieldName(), "clone") == 0 ) {
- valid = true;
- string err;
- ok = cloneFrom(e.valuestr(), err);
- if( !err.empty() )
- anObjBuilder.append("errmsg", err.c_str());
- }
else if( strcmp( e.fieldName(), "create") == 0 ) {
valid = true;
string ns = us + '.' + e.valuestr();
diff --git a/db/commands.h b/db/commands.h
index 884c761d09b..062867a1997 100644
--- a/db/commands.h
+++ b/db/commands.h
@@ -31,10 +31,5 @@ public:
/* return true if only the admin ns has privileges to run this command. */
virtual bool adminOnly() { return false; }
- static map<string,Command*> commands;
-
- Command(const char *_name) : name(_name) {
- // register ourself.
- commands[name] = this;
- }
+ Command(const char *_name);
};