-#if defined(__NetBSD__)
-#define MDB_SHORT_SEMNAMES 1 /* limited to 14 chars */
-#endif
- if (fstat(env->me_lfd, &stbuf)) goto fail_errno;
- idbuf.dev = stbuf.st_dev;
- idbuf.ino = stbuf.st_ino;
- val.mv_data = &idbuf;
- val.mv_size = sizeof(idbuf);
- mdb_hash_enc(&val, encbuf);
-#ifdef MDB_SHORT_SEMNAMES
- encbuf[9] = '\0'; /* drop name from 15 chars to 14 chars */
-#endif
- sprintf(env->me_txns->mti_rmname, "/MDBr%s", encbuf);
- sprintf(env->me_txns->mti_wmname, "/MDBw%s", encbuf);
- /* 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) goto fail_errno;
- env->me_wmutex = sem_open(env->me_txns->mti_wmname,
- O_CREAT|O_EXCL, mode, 1);
- if (env->me_wmutex == SEM_FAILED) goto fail_errno;
-#else /* MDB_USE_POSIX_SEM */
+ env->me_rmutex.semid = semid;
+ env->me_wmutex.semid = semid;
+ env->me_rmutex.semnum = 0;
+ env->me_wmutex.semnum = 1;
+
+ semu.array = vals;
+ if (semctl(semid, 0, SETALL, semu) < 0)
+ goto fail_errno;
+ env->me_txns->mti_semid = semid;
+#else /* MDB_USE_SYSV_SEM */