summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-29 11:02:32 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-29 11:02:32 +0000
commit4ae2b92576e8e9fc43906e9483c79eff9d0522f7 (patch)
tree4890cf79c2f4571079c7dd93a12a1fd011e7a1ec /io.c
parent3bffb5f3064b129941a2cf6f459aeb85e8469ea7 (diff)
* include/ruby/intern.h (rb_cloexec_dup): declared.
* io.c (rb_cloexec_dup): new function. (ruby_dup): use rb_cloexec_dup. * ext/pty/pty.c (pty_getpty): use rb_cloexec_dup. * ext/openssl/ossl_bio.c (ossl_obj2bio): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/io.c b/io.c
index 98484e8958..ddc89cc67e 100644
--- a/io.c
+++ b/io.c
@@ -200,6 +200,15 @@ rb_cloexec_open(const char *pathname, int flags, mode_t mode)
return ret;
}
+int
+rb_cloexec_dup(int oldfd)
+{
+ int ret;
+ ret = dup(oldfd);
+ if (ret == -1) return -1;
+ fd_set_cloexec(ret);
+ return ret;
+}
#define argf_of(obj) (*(struct argf *)DATA_PTR(obj))
#define ARGF argf_of(argf)
@@ -561,17 +570,17 @@ ruby_dup(int orig)
{
int fd;
- fd = dup(orig);
+ fd = rb_cloexec_dup(orig);
if (fd < 0) {
if (errno == EMFILE || errno == ENFILE || errno == ENOMEM) {
rb_gc();
- fd = dup(orig);
+ fd = rb_cloexec_dup(orig);
}
if (fd < 0) {
rb_sys_fail(0);
}
}
- rb_fd_set_cloexec(fd);
+ rb_update_max_fd(fd);
return fd;
}