From c6c693fdcc1bf49b8cc8065d7a5b2cfac6f27e6d Mon Sep 17 00:00:00 2001 From: Geir Magnusson Jr Date: Wed, 30 Apr 2008 08:47:31 -0400 Subject: [PATCH] DB-1 : ensure that there's a trailing slash for dbpath (otherwise bad things happen) --- db/db.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/db/db.cpp b/db/db.cpp index 58aa29dfd7b0e..1e9fc21eaf462 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;