ITS#7364 Always sem_unlink() in mdb_env_open().

Drop the sem_unlink() error checks, which could prevent the 2nd
unlink.  Instead use O_EXCL in sem_open().

This makes "open+close the database" the API for trying to clean
away the old semaphores, if they were left behind by a previous run.
vmware
Hallvard Furuseth 12 years ago
parent 31be24896b
commit c760e536ec
  1. 25
      libraries/libmdb/mdb.c

@ -3006,12 +3006,12 @@ mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl)
val.mv_size = sizeof(idbuf); val.mv_size = sizeof(idbuf);
mdb_hash_hex(&val, hexbuf); mdb_hash_hex(&val, hexbuf);
sprintf(env->me_txns->mti_rmname, "Global\\MDBr%s", hexbuf); sprintf(env->me_txns->mti_rmname, "Global\\MDBr%s", hexbuf);
sprintf(env->me_txns->mti_wmname, "Global\\MDBw%s", hexbuf);
env->me_rmutex = CreateMutex(&mdb_all_sa, FALSE, env->me_txns->mti_rmname); env->me_rmutex = CreateMutex(&mdb_all_sa, FALSE, env->me_txns->mti_rmname);
if (!env->me_rmutex) { if (!env->me_rmutex) {
rc = ErrCode(); rc = ErrCode();
goto fail; goto fail;
} }
sprintf(env->me_txns->mti_wmname, "Global\\MDBw%s", hexbuf);
env->me_wmutex = CreateMutex(&mdb_all_sa, FALSE, env->me_txns->mti_wmname); env->me_wmutex = CreateMutex(&mdb_all_sa, FALSE, env->me_txns->mti_wmname);
if (!env->me_wmutex) { if (!env->me_wmutex) {
rc = ErrCode(); rc = ErrCode();
@ -3033,23 +3033,20 @@ mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl)
val.mv_size = sizeof(idbuf); val.mv_size = sizeof(idbuf);
mdb_hash_hex(&val, hexbuf); mdb_hash_hex(&val, hexbuf);
sprintf(env->me_txns->mti_rmname, "/MDBr%s", hexbuf); sprintf(env->me_txns->mti_rmname, "/MDBr%s", hexbuf);
if (sem_unlink(env->me_txns->mti_rmname)) {
rc = ErrCode();
if (rc != ENOENT && rc != EINVAL)
goto fail;
}
env->me_rmutex = sem_open(env->me_txns->mti_rmname, O_CREAT, mode, 1);
if (env->me_rmutex == SEM_FAILED) {
rc = ErrCode();
goto fail;
}
sprintf(env->me_txns->mti_wmname, "/MDBw%s", hexbuf); sprintf(env->me_txns->mti_wmname, "/MDBw%s", hexbuf);
if (sem_unlink(env->me_txns->mti_wmname)) { /* Clean up after a previous run, if needed: Try to
* remove both semaphores before doing anything else.
*/
sem_unlink(env->me_txns->mti_rmname);
sem_unlink(env->me_txns->mti_wmname);
env->me_rmutex = sem_open(env->me_txns->mti_rmname,
O_CREAT|O_EXCL, mode, 1);
if (env->me_rmutex == SEM_FAILED) {
rc = ErrCode(); rc = ErrCode();
if (rc != ENOENT && rc != EINVAL)
goto fail; goto fail;
} }
env->me_wmutex = sem_open(env->me_txns->mti_wmname, O_CREAT, mode, 1); env->me_wmutex = sem_open(env->me_txns->mti_wmname,
O_CREAT|O_EXCL, mode, 1);
if (env->me_wmutex == SEM_FAILED) { if (env->me_wmutex == SEM_FAILED) {
rc = ErrCode(); rc = ErrCode();
goto fail; goto fail;

Loading…
Cancel
Save