From 0a9cb21e6215e50cb1d81f9f984a09b2b09176c1 Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 29 Oct 2011 13:11:01 +0000 Subject: * 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 --- io.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index fad64cafe8..fadbb2ec90 100644 --- a/io.c +++ b/io.c @@ -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); -- cgit v1.2.3