From f40ba83d2fde18dc5dcc331c47f63943013c8e09 Mon Sep 17 00:00:00 2001 From: Yoni Fogel Date: Wed, 28 Nov 2007 14:50:09 +0000 Subject: [PATCH] Default env directory is '.' Add support for DB_USE_ENVIRON and DB_USE_ENVIRON_ROOT git-svn-id: file:///svn/tokudb@783 c7de825b-a66e-492c-adef-691d508d4ae1 --- src/ydb.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/ydb.c b/src/ydb.c index 9062c52b039..8b4e74610f8 100644 --- a/src/ydb.c +++ b/src/ydb.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "brt.h" #include "brt-internal.h" @@ -222,10 +223,22 @@ int __toku_db_env_open(DB_ENV * env, const char *home, u_int32_t flags, int mode if (db_env_opened(env)) return EINVAL; + + if ((flags & DB_USE_ENVIRON) && (flags & DB_USE_ENVIRON_ROOT)) return EINVAL; - if (!home) return EINVAL; - else { + + if (home) { + if ((flags & DB_USE_ENVIRON) || (flags & DB_USE_ENVIRON_ROOT)) return EINVAL; + } + else if ((flags & DB_USE_ENVIRON) || + ((flags & DB_USE_ENVIRON_ROOT) && geteuid() == 0)) { + home = getenv("DB_HOME"); + if (!home) return EINVAL; + } + else home = "."; + // Verify that the home exists. + { struct stat buf; r = stat(home, &buf); if (r!=0) return errno; @@ -250,11 +263,8 @@ int __toku_db_env_open(DB_ENV * env, const char *home, u_int32_t flags, int mode env->i->dir = NULL; return r; } - if ((r = db_env_read_config(env, flags)) != 0) { - fprintf(stderr, "FOO FOO FOO \n"); - goto died1; - } - + if ((r = db_env_read_config(env, flags)) != 0) goto died1; + env->i->open_flags = flags; env->i->open_mode = mode;