From: Howard Chu Date: Tue, 13 Aug 2013 20:12:47 +0000 (-0700) Subject: ITS#7664 better fix X-Git-Tag: OPENLDAP_REL_ENG_2_4_36~1^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=76f0a024859d3907305ec43b2f5826b45987d553;p=openldap ITS#7664 better fix For RDONLY, don't get lockfile until we know datafile exists. Also, don't try to create a new datafile for me_mfd if someone deleted it after we got me_fd. --- diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index 6460173591..ee7f77169a 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -3898,9 +3898,12 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode goto leave; } - rc = mdb_env_setup_locks(env, lpath, mode, &excl); - if (rc) - goto leave; + /* For RDONLY, get lockfile after we know datafile exists */ + if (!F_ISSET(flags, MDB_RDONLY)) { + rc = mdb_env_setup_locks(env, lpath, mode, &excl); + if (rc) + goto leave; + } #ifdef _WIN32 if (F_ISSET(flags, MDB_RDONLY)) { @@ -3926,6 +3929,12 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode goto leave; } + if (F_ISSET(flags, MDB_RDONLY)) { + rc = mdb_env_setup_locks(env, lpath, mode, &excl); + if (rc) + goto leave; + } + if ((rc = mdb_env_open2(env)) == MDB_SUCCESS) { if (flags & (MDB_RDONLY|MDB_WRITEMAP)) { env->me_mfd = env->me_fd; @@ -3934,10 +3943,12 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode * MDB_NOSYNC/MDB_NOMETASYNC, in case these get reset. */ #ifdef _WIN32 + len = OPEN_EXISTING; env->me_mfd = CreateFile(dpath, oflags, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, len, mode | FILE_FLAG_WRITE_THROUGH, NULL); #else + oflags &= ~O_CREAT; env->me_mfd = open(dpath, oflags | MDB_DSYNC, mode); #endif if (env->me_mfd == INVALID_HANDLE_VALUE) {