diff options
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | include/ruby/intern.h | 1 | ||||
-rw-r--r-- | io.c | 25 |
3 files changed, 33 insertions, 3 deletions
@@ -1,3 +1,13 @@ +Sat Oct 29 10:40:19 2011 Tanaka Akira <akr@fsij.org> + + * include/ruby/intern.h (rb_cloexec_open): declared. + + * io.c (fd_set_cloexec): extracted from rb_fd_set_cloexec. + (rb_cloexec_open): new function. + (sysopen_func): use rb_cloexec_open. + (rb_sysopen_internal): use rb_update_max_fd instead of + rb_fd_set_cloexec. + Sat Oct 29 09:05:07 2011 Nobuyoshi Nakada <nobu@ruby-lang.org> * thread_pthread.h: no Structured Exception Handling like macros. diff --git a/include/ruby/intern.h b/include/ruby/intern.h index cf31b8e3ab..5f8d1ae929 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -502,6 +502,7 @@ void rb_write_error2(const char*, long); void rb_close_before_exec(int lowfd, int maxhint, VALUE noclose_fds); int rb_pipe(int *pipes); int rb_reserved_fd_p(int fd); +int rb_cloexec_open(const char *pathname, int flags, mode_t mode); #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); @@ -157,7 +157,8 @@ rb_update_max_fd(int fd) if (max_file_descriptor < fd) max_file_descriptor = fd; } -void rb_fd_set_cloexec(int fd) +static void +fd_set_cloexec(int fd) { /* MinGW don't have F_GETFD and FD_CLOEXEC. [ruby-core:40281] */ #ifdef F_GETFD @@ -176,9 +177,27 @@ void rb_fd_set_cloexec(int fd) } } #endif +} + +void +rb_fd_set_cloexec(int fd) +{ + fd_set_cloexec(fd); if (max_file_descriptor < fd) max_file_descriptor = fd; } + +int +rb_cloexec_open(const char *pathname, int flags, mode_t mode) +{ + int ret; + ret = open(pathname, flags, mode); + 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) @@ -4604,7 +4623,7 @@ sysopen_func(void *ptr) { const struct sysopen_struct *data = ptr; const char *fname = RSTRING_PTR(data->fname); - return (VALUE)open(fname, data->oflags, data->perm); + return (VALUE)rb_cloexec_open(fname, data->oflags, data->perm); } static inline int @@ -4613,7 +4632,7 @@ rb_sysopen_internal(struct sysopen_struct *data) int fd; fd = (int)rb_thread_blocking_region(sysopen_func, data, RUBY_UBF_IO, 0); if (0 <= fd) - rb_fd_set_cloexec(fd); + rb_update_max_fd(fd); return fd; } |