From 0d2a92e0b327bd69781dd51f34278e843d5f0b74 Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 30 Oct 2011 12:13:05 +0000 Subject: * include/ruby/intern.h (rb_cloexec_pipe): declared. * io.c (rb_cloexec_pipe): new function. (rb_pipe): use rb_cloexec_pipe. * thread_pthread.c (rb_thread_create_timer_thread): use rb_cloexec_pipe. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index 4dbf337e8c..33b7382ab4 100644 --- a/io.c +++ b/io.c @@ -262,6 +262,25 @@ rb_cloexec_dup2(int oldfd, int newfd) return ret; } +int +rb_cloexec_pipe(int fildes[2]) +{ + int ret; + ret = pipe(fildes); + if (ret == -1) return -1; +#ifdef __CYGWIN__ + if (ret == 0 && fildes[1] == -1) { + close(fildes[0]); + fildes[0] = -1; + errno = ENFILE; + return -1; + } +#endif + fd_set_cloexec(fildes[0]); + fd_set_cloexec(fildes[1]); + return ret; +} + #define argf_of(obj) (*(struct argf *)DATA_PTR(obj)) #define ARGF argf_of(argf) @@ -5008,24 +5027,16 @@ int rb_pipe(int *pipes) { int ret; - ret = pipe(pipes); + ret = rb_cloexec_pipe(pipes); if (ret == -1) { if (errno == EMFILE || errno == ENFILE) { rb_gc(); - ret = pipe(pipes); + ret = rb_cloexec_pipe(pipes); } } -#ifdef __CYGWIN__ - if (ret == 0 && pipes[1] == -1) { - close(pipes[0]); - pipes[0] = -1; - errno = ENFILE; - return -1; - } -#endif if (ret == 0) { - rb_fd_set_cloexec(pipes[0]); - rb_fd_set_cloexec(pipes[1]); + rb_update_max_fd(pipes[0]); + rb_update_max_fd(pipes[1]); } return ret; } -- cgit v1.2.3