From: Hallvard Furuseth Date: Sat, 1 Jul 2017 11:15:37 +0000 (+0200) Subject: Get flags from $LMDB_FLAGS when MDB_TEST X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de161fe9d963fa3b2af4e60f861ef6e0d2d607c3;p=thirdparty%2Fopenldap.git Get flags from $LMDB_FLAGS when MDB_TEST Now we don't need to tweak the code of callers to test encryption. --- diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index 2e91fece3d..d6260d329c 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -5463,6 +5463,34 @@ fail: return rc; } +#ifdef MDB_TEST +/** Add #mdb_env_open() flags from environment variable $LMDB_FLAGS. + */ +static int ESECT +mdb_env_getflags(MDB_env *env) +{ + static const char names[] = "acfhilmnrstw"; + static const unsigned f[] = { + MDB_MAPASYNC, MDB_REMAP_CHUNKS, MDB_FIXEDMAP, MDB_NORDAHEAD, + MDB_NOMEMINIT, MDB_NOLOCK, MDB_NOMETASYNC, MDB_NOSUBDIR, + MDB_RDONLY, MDB_NOSYNC, MDB_NOTLS, MDB_WRITEMAP, + }; + unsigned flags = 0; + const char *s, *opts = getenv("LMDB_FLAGS"); + if (opts) { + for (; *opts; opts++) { + if ((s = strchr(names, *opts)) == NULL) + return EINVAL; + flags |= f[s - names]; + } + env->me_flags |= flags; + } + return MDB_SUCCESS; +} +#else +#define mdb_env_getflags(env) MDB_SUCCESS +#endif /* MDB_TEST */ + /** Only a subset of the @ref mdb_env flags can be changed * at runtime. Changing other flags requires closing the * environment and re-opening it with the new flags. @@ -5484,7 +5512,10 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode if (env->me_fd!=INVALID_HANDLE_VALUE || (flags & ~(CHANGEABLE|CHANGELESS))) return EINVAL; + if ((rc = mdb_env_getflags(env)) != MDB_SUCCESS) + return rc; flags |= env->me_flags; + if (MDB_REMAPPING(0)) /* if we always remap chunks */ flags |= MDB_REMAP_CHUNKS; if (MDB_REMAPPING(flags)) {