diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-10-29 13:11:01 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-10-29 13:11:01 +0000 |
commit | 0a9cb21e6215e50cb1d81f9f984a09b2b09176c1 (patch) | |
tree | 5eec4bee3a326a55d49d4e03f70989f7ea3b220c /io.c | |
parent | 195fbd18d61c336b510f63ea83dbf6483523aee2 (diff) | |
download | ruby-0a9cb21e6215e50cb1d81f9f984a09b2b09176c1.tar.gz |
* include/ruby/intern.h (rb_cloexec_dup2): declared.
* io.c (rb_cloexec_dup2): new function.
(io_reopen): use rb_cloexec_dup2.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33557 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -227,6 +227,17 @@ rb_cloexec_dup(int oldfd) return ret; } +int +rb_cloexec_dup2(int oldfd, int newfd) +{ + int ret; + + ret = dup2(oldfd, newfd); + 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) @@ -5870,17 +5881,17 @@ io_reopen(VALUE io, VALUE nfile) if (fd != fd2) { if (IS_PREP_STDIO(fptr) || fd <= 2 || !fptr->stdio_file) { /* need to keep FILE objects of stdin, stdout and stderr */ - if (dup2(fd2, fd) < 0) + if (rb_cloexec_dup2(fd2, fd) < 0) rb_sys_fail_path(orig->pathv); - rb_fd_set_cloexec(fd); + rb_update_max_fd(fd); } else { fclose(fptr->stdio_file); fptr->stdio_file = 0; fptr->fd = -1; - if (dup2(fd2, fd) < 0) + if (rb_cloexec_dup2(fd2, fd) < 0) rb_sys_fail_path(orig->pathv); - rb_fd_set_cloexec(fd); + rb_update_max_fd(fd); fptr->fd = fd; } rb_thread_fd_close(fd); |