1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* io.c (rb_cloexec_dup): use F_DUPFD_CLOEXEC if available.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33555 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2011-10-29 11:59:46 +00:00
parent a9648d1e58
commit 54d7e82613
2 changed files with 20 additions and 0 deletions

View file

@ -1,3 +1,7 @@
Sat Oct 29 20:59:08 2011 Tanaka Akira <akr@fsij.org>
* io.c (rb_cloexec_dup): use F_DUPFD_CLOEXEC if available.
Sat Oct 29 20:00:26 2011 Tanaka Akira <akr@fsij.org>
* include/ruby/intern.h (rb_cloexec_dup): declared.

16
io.c
View file

@ -205,7 +205,23 @@ int
rb_cloexec_dup(int oldfd)
{
int ret;
#ifdef F_DUPFD_CLOEXEC
static int try_fcntl = 1;
if (try_fcntl) {
ret = fcntl(oldfd, F_DUPFD_CLOEXEC, 0);
/* F_DUPFD_CLOEXEC is available since Linux 2.6.24. Linux 2.6.18 fails with EINVAL */
if (ret == -1 && errno == EINVAL) {
try_fcntl = 0;
ret = dup(oldfd);
}
}
else {
ret = dup(oldfd);
}
#else
ret = dup(oldfd);
#endif
if (ret == -1) return -1;
fd_set_cloexec(ret);
return ret;