summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Gorrod <alexg@wiredtiger.com>2013-03-18 14:23:14 +1100
committerAlex Gorrod <alexg@wiredtiger.com>2013-03-18 14:23:14 +1100
commitf67c917a34727e82c20cb5ee0aa115559076f9ea (patch)
tree0880d507b854173696bc92148ced96638f470a4a
parent9bea2a1b57bf724f5277a80f45c3067976be0e74 (diff)
downloadmongo-f67c917a34727e82c20cb5ee0aa115559076f9ea.tar.gz
Fix a bug where absolute path names URIs were not being parsed correctly
Also adjust the stat file logging name creation to do less allocations.
-rw-r--r--dist/s_string.ok1
-rw-r--r--src/conn/conn_stat.c14
-rw-r--r--src/include/extern.h4
-rw-r--r--src/support/filename.c28
4 files changed, 30 insertions, 17 deletions
diff --git a/dist/s_string.ok b/dist/s_string.ok
index 0b4118937d4..96c9a065227 100644
--- a/dist/s_string.ok
+++ b/dist/s_string.ok
@@ -537,6 +537,7 @@ negint
newbar
newname
nextprev
+nfilename
nhex
nl
nlpo
diff --git a/src/conn/conn_stat.c b/src/conn/conn_stat.c
index ef4c3b5f441..a24c3055422 100644
--- a/src/conn/conn_stat.c
+++ b/src/conn/conn_stat.c
@@ -58,7 +58,7 @@ __statlog_config(WT_SESSION_IMPL *session, const char **cfg, int *runp)
conn->stat_clear = cval.val != 0;
WT_RET(__wt_config_gets(session, cfg, "statistics_log.path", &cval));
- WT_RET(__wt_strndup(session, cval.str, cval.len, &conn->stat_path));
+ WT_RET(__wt_nfilename(session, cval.str, cval.len, &conn->stat_path));
WT_RET(__wt_config_gets(
session, cfg, "statistics_log.timestamp", &cval));
@@ -84,7 +84,7 @@ __stat_server(void *arg)
WT_SESSION *wt_session;
WT_SESSION_IMPL *session;
uint64_t value;
- const char *config, *desc, *pdesc, *p;
+ const char *config, *desc, *pdesc;
session = arg;
conn = S2C(session);
@@ -96,16 +96,6 @@ __stat_server(void *arg)
fp = NULL;
/*
- * If the logging file name beings with an absolute path, use it as is,
- * otherwise build a version relative to the database home directory.
- */
- if (!__wt_absolute_path(conn->stat_path)) {
- WT_ERR(__wt_filename(session, conn->stat_path, &p));
- __wt_free(session, conn->stat_path);
- conn->stat_path = p;
- }
-
- /*
* We need a temporary place to build a path and an entry prefix.
* The length of the path plus 128 should be more than enough.
*
diff --git a/src/include/extern.h b/src/include/extern.h
index c0142791879..2a9fd454342 100644
--- a/src/include/extern.h
+++ b/src/include/extern.h
@@ -1144,6 +1144,10 @@ extern int __wt_absolute_path(const char *path);
extern int __wt_filename(WT_SESSION_IMPL *session,
const char *name,
const char **path);
+extern int __wt_nfilename(WT_SESSION_IMPL *session,
+ const char *name,
+ size_t namelen,
+ const char **path);
extern int __wt_library_init(void);
extern int __wt_breakpoint(void);
extern void __wt_attach(WT_SESSION_IMPL *session);
diff --git a/src/support/filename.c b/src/support/filename.c
index 57f3de97d65..6b3d7ff17d2 100644
--- a/src/support/filename.c
+++ b/src/support/filename.c
@@ -19,11 +19,25 @@ __wt_absolute_path(const char *path)
/*
* __wt_filename --
- * Build a filename in a scratch buffer.
+ * Build a file name in a scratch buffer, automatically calculate the
+ * length of the file name.
*/
int
__wt_filename(WT_SESSION_IMPL *session, const char *name, const char **path)
{
+ return __wt_nfilename(session, name, strlen(name), path);
+}
+
+/*
+ * __wt_nfilename --
+ * Build a file name in a scratch buffer. If the name is already an
+ * absolute path duplicate it, otherwise generate a path relative to the
+ * connection home directory.
+ */
+int
+__wt_nfilename(WT_SESSION_IMPL *session,
+ const char *name, size_t namelen, const char **path)
+{
WT_CONNECTION_IMPL *conn;
size_t len;
char *buf;
@@ -31,10 +45,14 @@ __wt_filename(WT_SESSION_IMPL *session, const char *name, const char **path)
conn = S2C(session);
*path = NULL;
- len = strlen(conn->home) + 1 + strlen(name) + 1;
- WT_RET(__wt_calloc(session, 1, len, &buf));
- snprintf(buf, len, "%s/%s", conn->home, name);
+ if (__wt_absolute_path(name))
+ WT_RET(__wt_strndup(session, name, namelen, path));
+ else {
+ len = strlen(conn->home) + 1 + namelen + 1;
+ WT_RET(__wt_calloc(session, 1, len, &buf));
+ snprintf(buf, len, "%s/%.*s", conn->home, (int)namelen, name);
+ *path = buf;
+ }
- *path = buf;
return (0);
}