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 | |
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
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | include/ruby/intern.h | 1 | ||||
-rw-r--r-- | io.c | 19 |
3 files changed, 23 insertions, 4 deletions
@@ -1,3 +1,10 @@ +Sat Oct 29 22:06:37 2011 Tanaka Akira <akr@fsij.org> + + * 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 <artonx@yahoo.co.jp> * 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); @@ -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); |