summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2014-12-19 13:46:01 -0500
committerMark Benvenuto <mark.benvenuto@mongodb.com>2014-12-19 17:18:30 -0500
commitb896fb9a7072c4d2b43ed9c19a39fe342bd4d094 (patch)
tree397c3a86df94485b476fbab19b805f6c84061294
parentafd499a7091dab914463692dcc442a308740e33c (diff)
downloadmongo-b896fb9a7072c4d2b43ed9c19a39fe342bd4d094.tar.gz
Add __wt_getenv to workaround caching in MSVC CRT's getenv implementation.
-rw-r--r--build_win/filelist.win1
-rw-r--r--dist/filelist1
-rw-r--r--dist/s_string.ok2
-rwxr-xr-xdist/s_win1
-rw-r--r--src/conn/conn_api.c33
-rw-r--r--src/include/extern.h1
-rw-r--r--src/os_posix/os_getenv.c26
-rw-r--r--src/os_win/os_getenv.c35
8 files changed, 87 insertions, 13 deletions
diff --git a/build_win/filelist.win b/build_win/filelist.win
index c7903c0a161..78ddcb14a59 100644
--- a/build_win/filelist.win
+++ b/build_win/filelist.win
@@ -113,6 +113,7 @@ src/os_win/os_filesize.c
src/os_win/os_flock.c
src/os_win/os_fsync.c
src/os_win/os_ftruncate.c
+src/os_win/os_getenv.c
src/os_win/os_map.c
src/os_win/os_mtx_cond.c
src/os_win/os_once.c
diff --git a/dist/filelist b/dist/filelist
index 07469f49311..c2346caf1ea 100644
--- a/dist/filelist
+++ b/dist/filelist
@@ -109,6 +109,7 @@ src/os_posix/os_filesize.c
src/os_posix/os_flock.c
src/os_posix/os_fsync.c
src/os_posix/os_ftruncate.c
+src/os_posix/os_getenv.c
src/os_posix/os_getline.c
src/os_posix/os_getopt.c
src/os_posix/os_map.c
diff --git a/dist/s_string.ok b/dist/s_string.ok
index aa5d65bcc8b..94f3ea6b6a5 100644
--- a/dist/s_string.ok
+++ b/dist/s_string.ok
@@ -138,6 +138,7 @@ GETTIMEOFDAY
GIDs
Gcc
Geoff
+GetEnvironmentVariableA
GetFileAttributesEx
GetFileSizeEx
GetLastError
@@ -639,6 +640,7 @@ func
funcs
gcc
gdb
+getenv
getfiles
getid
getline
diff --git a/dist/s_win b/dist/s_win
index 7c5fecb08bc..187de91e498 100755
--- a/dist/s_win
+++ b/dist/s_win
@@ -44,6 +44,7 @@ win_filelist()
-e 's;os_posix/os_flock.c;os_win/os_flock.c;' \
-e 's;os_posix/os_fsync.c;os_win/os_fsync.c;' \
-e 's;os_posix/os_ftruncate.c;os_win/os_ftruncate.c;' \
+ -e 's;os_posix/os_getenv.c;os_win/os_getenv.c;' \
-e 's;os_posix/os_map.c;os_win/os_map.c;' \
-e 's;os_posix/os_mtx_cond.c;os_win/os_mtx_cond.c;' \
-e 's;os_posix/os_once.c;os_win/os_once.c;' \
diff --git a/src/conn/conn_api.c b/src/conn/conn_api.c
index cc88f848861..33e04826644 100644
--- a/src/conn/conn_api.c
+++ b/src/conn/conn_api.c
@@ -1007,15 +1007,17 @@ static int
__conn_config_env(WT_SESSION_IMPL *session, const char *cfg[], WT_ITEM *cbuf)
{
WT_CONFIG_ITEM cval;
+ WT_DECL_RET;
const char *env_config;
size_t len;
- if ((env_config = getenv("WIREDTIGER_CONFIG")) == NULL)
+ ret = __wt_getenv(session, "WIREDTIGER_CONFIG", &env_config);
+ if (ret == WT_NOTFOUND)
return (0);
len = strlen(env_config);
if (len == 0)
return (0);
- WT_RET(__wt_buf_set(session, cbuf, env_config, len + 1));
+ WT_ERR(__wt_buf_set(session, cbuf, env_config, len + 1));
/*
* Security stuff:
@@ -1023,26 +1025,29 @@ __conn_config_env(WT_SESSION_IMPL *session, const char *cfg[], WT_ITEM *cbuf)
* If the "use_environment_priv" configuration string is set, use the
* environment variable if the process has appropriate privileges.
*/
- WT_RET(__wt_config_gets(session, cfg, "use_environment_priv", &cval));
+ WT_ERR(__wt_config_gets(session, cfg, "use_environment_priv", &cval));
if (cval.val == 0 && __wt_has_priv())
- WT_RET_MSG(session, WT_ERROR, "%s",
+ WT_ERR_MSG(session, WT_ERROR, "%s",
"WIREDTIGER_CONFIG environment variable set but process "
"lacks privileges to use that environment variable");
/* Check any version. */
- WT_RET(__conn_config_check_version(session, env_config));
+ WT_ERR(__conn_config_check_version(session, env_config));
/* Upgrade the configuration string. */
- WT_RET(__wt_config_upgrade(session, cbuf));
+ WT_ERR(__wt_config_upgrade(session, cbuf));
/* Check the configuration information. */
- WT_RET(__wt_config_check(session,
+ WT_ERR(__wt_config_check(session,
WT_CONFIG_REF(session, wiredtiger_open), env_config, 0));
/* Append it to the stack. */
- __conn_config_append(cfg, env_config);
+ __conn_config_append(cfg, cbuf->data);
- return (0);
+err: if (env_config != NULL)
+ __wt_free(session, env_config);
+
+ return (ret);
}
/*
@@ -1052,17 +1057,19 @@ __conn_config_env(WT_SESSION_IMPL *session, const char *cfg[], WT_ITEM *cbuf)
static int
__conn_home(WT_SESSION_IMPL *session, const char *home, const char *cfg[])
{
+ WT_DECL_RET;
WT_CONFIG_ITEM cval;
/* If the application specifies a home directory, use it. */
if (home != NULL)
goto copy;
+ ret = __wt_getenv(session, "WIREDTIGER_HOME", &S2C(session)->home);
+ if (ret == 0)
+ return (0);
+
/* If there's no WIREDTIGER_HOME environment variable, use ".". */
- if ((home = getenv("WIREDTIGER_HOME")) == NULL || strlen(home) == 0) {
- home = ".";
- goto copy;
- }
+ home = ".";
/*
* Security stuff:
diff --git a/src/include/extern.h b/src/include/extern.h
index bb7caa991d6..99323a0b126 100644
--- a/src/include/extern.h
+++ b/src/include/extern.h
@@ -442,6 +442,7 @@ extern int __wt_directory_sync(WT_SESSION_IMPL *session, char *path);
extern int __wt_fsync(WT_SESSION_IMPL *session, WT_FH *fh);
extern int __wt_fsync_async(WT_SESSION_IMPL *session, WT_FH *fh);
extern int __wt_ftruncate(WT_SESSION_IMPL *session, WT_FH *fh, wt_off_t len);
+extern int __wt_getenv(WT_SESSION_IMPL *session, const char *variable, const char **env);
extern int __wt_getline(WT_SESSION_IMPL *session, WT_ITEM *buf, FILE *fp);
extern int __wt_getopt( const char *progname, int nargc, char *const *nargv, const char *ostr);
extern int __wt_mmap(WT_SESSION_IMPL *session, WT_FH *fh, void *mapp, size_t *lenp, void **mappingcookie);
diff --git a/src/os_posix/os_getenv.c b/src/os_posix/os_getenv.c
new file mode 100644
index 00000000000..83cf8a75770
--- /dev/null
+++ b/src/os_posix/os_getenv.c
@@ -0,0 +1,26 @@
+/*-
+ * Copyright (c) 2008-2014 WiredTiger, Inc.
+ * All rights reserved.
+ *
+ * See the file LICENSE for redistribution information.
+ */
+
+#include "wt_internal.h"
+
+/*
+ * __wt_getenv --
+ * Get a non-null environment variable
+ */
+int
+__wt_getenv(WT_SESSION_IMPL *session, const char *variable, const char **env)
+{
+ const char *temp;
+
+ *env = NULL;
+
+ if (((temp = getenv(variable)) != NULL) && strlen(temp) > 0) {
+ return (__wt_strdup(session, temp, env));
+ }
+
+ return (WT_NOTFOUND);
+}
diff --git a/src/os_win/os_getenv.c b/src/os_win/os_getenv.c
new file mode 100644
index 00000000000..31505266d76
--- /dev/null
+++ b/src/os_win/os_getenv.c
@@ -0,0 +1,35 @@
+/*-
+ * Copyright (c) 2008-2014 WiredTiger, Inc.
+ * All rights reserved.
+ *
+ * See the file LICENSE for redistribution information.
+ */
+
+#include "wt_internal.h"
+
+/*
+ * __wt_getenv --
+ * Get a non-null environment variable
+ */
+int
+__wt_getenv(WT_SESSION_IMPL *session, const char *variable, const char **env)
+{
+ WT_DECL_RET;
+ DWORD size;
+
+ *env = NULL;
+
+ size = GetEnvironmentVariableA(variable, NULL, 0);
+ if (size <= 1)
+ return (WT_NOTFOUND);
+
+ WT_RET(__wt_calloc(session, 1, size, env));
+
+ ret = GetEnvironmentVariableA(variable, *env, size);
+ /* We expect the number of bytes not including null terminator */
+ if ((ret + 1) != size)
+ WT_RET_MSG(session, __wt_errno(),
+ "GetEnvironmentVariableA failed: %s", variable);
+
+ return (0);
+}