diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-10-30 15:17:27 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-10-30 15:17:27 +0000 |
commit | 5c19f077008f6e6633e15a8d15fceb4b17d37208 (patch) | |
tree | 435a57136340ae2903a394b2743e23f4a6a12ea9 | |
parent | e7f8c03818873b7cd64cb5080fe329098352af6c (diff) | |
download | ruby-5c19f077008f6e6633e15a8d15fceb4b17d37208.tar.gz |
* include/ruby/intern.h (rb_cloexec_fcntl_dupfd): declared.
* io.c (rb_cloexec_fcntl_dupfd): new function.
(nogvl_io_cntl): use rb_cloexec_fcntl_dupfd.
* process.c (move_fds_to_avoid_crash): use rb_cloexec_fcntl_dupfd.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | include/ruby/intern.h | 1 | ||||
-rw-r--r-- | io.c | 17 | ||||
-rw-r--r-- | process.c | 4 |
4 files changed, 27 insertions, 4 deletions
@@ -1,3 +1,12 @@ +Mon Oct 31 00:16:11 2011 Tanaka Akira <akr@fsij.org> + + * include/ruby/intern.h (rb_cloexec_fcntl_dupfd): declared. + + * io.c (rb_cloexec_fcntl_dupfd): new function. + (nogvl_io_cntl): use rb_cloexec_fcntl_dupfd. + + * process.c (move_fds_to_avoid_crash): use rb_cloexec_fcntl_dupfd. + Sun Oct 30 22:46:46 2011 Tanaka Akira <akr@fsij.org> * configure.in: check pipe2. diff --git a/include/ruby/intern.h b/include/ruby/intern.h index de2fdbd57b..aa24d435f6 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -506,6 +506,7 @@ 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); int rb_cloexec_pipe(int fildes[2]); +int rb_cloexec_fcntl_dupfd(int fd, int minfd); #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); @@ -299,6 +299,16 @@ rb_cloexec_pipe(int fildes[2]) return ret; } +int +rb_cloexec_fcntl_dupfd(int fd, int minfd) +{ + int ret; + ret = fcntl(fd, F_DUPFD, minfd); + 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) @@ -7821,7 +7831,10 @@ static VALUE nogvl_io_cntl(void *ptr) if (arg->io_p) return (VALUE)ioctl(arg->fd, arg->cmd, arg->narg); else - return (VALUE)fcntl(arg->fd, arg->cmd, arg->narg); + if (arg->cmd == F_DUPFD) + return (VALUE)rb_cloexec_fcntl_dupfd(arg->fd, arg->narg); + else + return (VALUE)fcntl(arg->fd, arg->cmd, arg->narg); } static int @@ -7844,7 +7857,7 @@ io_cntl(int fd, int cmd, long narg, int io_p) retval = (int)rb_thread_io_blocking_region(nogvl_io_cntl, &arg, fd); #if defined(F_DUPFD) if (!io_p && retval != -1 && cmd == F_DUPFD) { - rb_fd_set_cloexec(retval); + rb_update_max_fd(retval); } #endif @@ -2508,10 +2508,10 @@ move_fds_to_avoid_crash(int *fdp, int n, VALUE fds) min = fdp[i]+1; while (RTEST(rb_hash_lookup(fds, INT2FIX(min)))) min++; - ret = fcntl(fdp[i], F_DUPFD, min); + ret = rb_cloexec_fcntl_dupfd(fdp[i], min); if (ret == -1) return -1; - rb_fd_set_cloexec(ret); + rb_update_max_fd(ret); close(fdp[i]); fdp[i] = ret; } |