From 0a9cb21e6215e50cb1d81f9f984a09b2b09176c1 Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 29 Oct 2011 13:11:01 +0000 Subject: [PATCH] * 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 --- ChangeLog | 7 +++++++ include/ruby/intern.h | 1 + io.c | 19 +++++++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index d4eaa0a2ea..c0ae04d8e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sat Oct 29 22:06:37 2011 Tanaka Akira + + * include/ruby/intern.h (rb_cloexec_dup2): declared. + + * io.c (rb_cloexec_dup2): new function. + (io_reopen): use rb_cloexec_dup2. + Sat Oct 20 21:08:18 2011 Tajima Akil * win32/Makefile.sub (CONFIG_H): have stdint.h if VC2010. diff --git a/include/ruby/intern.h b/include/ruby/intern.h index b1a86586a5..626bcf193f 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -504,6 +504,7 @@ int rb_pipe(int *pipes); int rb_reserved_fd_p(int fd); int rb_cloexec_open(const char *pathname, int flags, mode_t mode); int rb_cloexec_dup(int oldfd); +int rb_cloexec_dup2(int oldfd, int newfd); #define RB_RESERVED_FD_P(fd) rb_reserved_fd_p(fd) void rb_update_max_fd(int fd); void rb_fd_set_cloexec(int fd); 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);