mdbx: use O_CLOEXEC/FD_CLOEXEC for me_fd,env_copy as well (ITS#8505).

Change-Id: I1db158f1371e557a78fc11fc0ca9e371d1590067
This commit is contained in:
Leo Yuriev 2016-10-25 08:50:11 +03:00
parent 9a8270f427
commit 38d57e66c6

14
mdb.c
View File

@ -4723,7 +4723,7 @@ mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl)
/* Lose record locks when exec*() */
if ((fdflags = fcntl(env->me_lfd, F_GETFD) | FD_CLOEXEC) >= 0)
fcntl(env->me_lfd, F_SETFD, fdflags);
fcntl(env->me_lfd, F_SETFD, fdflags);
if (!(env->me_flags & MDB_NOTLS)) {
rc = pthread_key_create(&env->me_txkey, mdb_env_reader_destr);
@ -4902,12 +4902,16 @@ mdbx_env_open_ex(MDB_env *env, const char *path, unsigned flags, mode_t mode, in
else
oflags = O_RDWR | O_CREAT;
env->me_fd = open(dpath, oflags, mode);
env->me_fd = open(dpath, oflags|O_CLOEXEC, mode);
if (env->me_fd == INVALID_HANDLE_VALUE) {
rc = errno;
goto leave;
}
int fdflags;
if ((fdflags = fcntl(env->me_fd, F_GETFD) | FD_CLOEXEC) >= 0)
fcntl(env->me_fd, F_SETFD, fdflags);
if (flags & MDB_RDONLY) {
rc = mdb_env_setup_locks(env, lpath, mode, &excl);
if (rc)
@ -9543,12 +9547,16 @@ mdb_env_copy2(MDB_env *env, const char *path, unsigned flags)
* We don't want the OS to cache the writes, since the source data is
* already in the OS cache.
*/
newfd = open(lpath, O_WRONLY|O_CREAT|O_EXCL, 0666);
newfd = open(lpath, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0666);
if (newfd == INVALID_HANDLE_VALUE) {
rc = errno;
goto leave;
}
int fdflags;
if ((fdflags = fcntl(newfd, F_GETFD) | FD_CLOEXEC) >= 0)
fcntl(newfd, F_SETFD, fdflags);
if (env->me_psize >= env->me_os_psize) {
#ifdef F_NOCACHE /* __APPLE__ */
(void) fcntl(newfd, F_NOCACHE, 1);