mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/sdbm/_sdbm.c (sdbm_prep): set FD_CLOEXEC flags for file
descriptors. (fd_set_cloexec): new function. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33541 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a5a7e2cd91
commit
509ed0d94f
2 changed files with 31 additions and 0 deletions
|
@ -1,3 +1,9 @@
|
|||
Fri Oct 28 06:06:08 2011 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* ext/sdbm/_sdbm.c (sdbm_prep): set FD_CLOEXEC flags for file
|
||||
descriptors.
|
||||
(fd_set_cloexec): new function.
|
||||
|
||||
Fri Oct 28 03:01:27 2011 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||
|
||||
* vm_insnhelper.c (vm_call_cfunc): adding back useless hack. For some
|
||||
|
|
|
@ -178,6 +178,29 @@ sdbm_open(register char *file, register int flags, register int mode)
|
|||
return db;
|
||||
}
|
||||
|
||||
static int
|
||||
fd_set_cloexec(int fd)
|
||||
{
|
||||
/* MinGW don't have F_GETFD and FD_CLOEXEC. [ruby-core:40281] */
|
||||
#ifdef F_GETFD
|
||||
int flags, ret;
|
||||
flags = fcntl(fd, F_GETFD); /* should not fail except EBADF. */
|
||||
if (flags == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (2 < fd) {
|
||||
if (!(flags & FD_CLOEXEC)) {
|
||||
flags |= FD_CLOEXEC;
|
||||
ret = fcntl(fd, F_SETFD, flags);
|
||||
if (ret == -1) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
DBM *
|
||||
sdbm_prep(char *dirname, char *pagname, int flags, int mode)
|
||||
{
|
||||
|
@ -209,7 +232,9 @@ sdbm_prep(char *dirname, char *pagname, int flags, int mode)
|
|||
flags |= O_BINARY;
|
||||
|
||||
if ((db->pagf = open(pagname, flags, mode)) == -1) goto err;
|
||||
if (fd_set_cloexec(db->pagf) == -1) goto err;
|
||||
if ((db->dirf = open(dirname, flags, mode)) == -1) goto err;
|
||||
if (fd_set_cloexec(db->dirf) == -1) goto err;
|
||||
/*
|
||||
* need the dirfile size to establish max bit number.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue