]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
Get flags from $LMDB_FLAGS when MDB_TEST
authorHallvard Furuseth <hallvard@openldap.org>
Sat, 1 Jul 2017 11:15:37 +0000 (13:15 +0200)
committerHoward Chu <hyc@openldap.org>
Sat, 10 Oct 2020 11:52:51 +0000 (12:52 +0100)
Now we don't need to tweak the code of callers to test encryption.

libraries/liblmdb/mdb.c

index 2e91fece3d9a46243745b22c8561c498de2fbc8d..d6260d329c518c3c245c21b5602decf6effa0ba6 100644 (file)
@@ -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)) {