summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeir Magnusson Jr <geir@geir-magnusson-jrs-mac-pro.local>2008-04-30 08:47:31 -0400
committerGeir Magnusson Jr <geir@geir-magnusson-jrs-mac-pro.local>2008-04-30 08:47:31 -0400
commitc6c693fdcc1bf49b8cc8065d7a5b2cfac6f27e6d (patch)
tree82d6b41688d4ad00b638419fbceb917efa622d48
parent50f7e4dc7a192e879e6d3cc9515428d3efb39aef (diff)
downloadmongo-c6c693fdcc1bf49b8cc8065d7a5b2cfac6f27e6d.tar.gz
DB-1 : ensure that there's a trailing slash for dbpath
(otherwise bad things happen)
-rw-r--r--db/db.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/db/db.cpp b/db/db.cpp
index 58aa29dfd7b..1e9fc21eaf4 100644
--- a/db/db.cpp
+++ b/db/db.cpp
@@ -687,6 +687,8 @@ int main(int argc, char* argv[], char *envp[] )
* slightly different mode where "run" is assumed and we can set values
*/
+ char *dbDataPath = null;
+
for (int i = 1; i < argc; i++) {
char *s = argv[i];
@@ -695,11 +697,31 @@ int main(int argc, char* argv[], char *envp[] )
port = atoi(argv[++i]);
}
else if (s && strcmp(s, "--dbpath") == 0) {
- dbpath = argv[++i];
+ dbDataPath = strdup(argv[++i]);
}
}
+
+ if (!dbDataPath) {
+ dbDataPath = strdup(dbpath);
+ }
- initAndListen(port, dbpath);
+ /*
+ * ensure that the dbpath ends w/ '/' as that's key in preventing things like
+ * /data/dbadmin.ns
+ */
+
+ if (dbDataPath && dbDataPath[strlen(dbDataPath)-1] != '/') {
+ char *t = (char *) malloc(strlen(dbDataPath) + 2);
+
+ strcpy(t, dbDataPath);
+ strcat(t, "/");
+ free(dbDataPath);
+ dbDataPath = t;
+ }
+
+ initAndListen(port, dbDataPath);
+
+ free(dbDataPath); // be formal
goingAway = true;
return 0;