summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-03 21:56:59 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-03 21:56:59 +0000
commiteb35bb0b351f55459fdfce7198e8756e37141dff (patch)
treecad797d2e29e3bc8a6b8701b51e72c9e5b4ccf50 /io.c
parent4937a6dec45f33f7158565cfc65e24dc5b00dded (diff)
* include/ruby/intern.h, thread_pthread.c (rb_reserved_fd_p,
RB_RESERVED_FD_P): added. This C API is to limit to access fds which are used by RubyVM internal. In this version of CRuby, return 1 if fd is communication pipe. If your application needs to close all file descriptors to preent resource leak, skip internal fds using this C API. We also define a macro RB_RESERVED_FD_P(fd). So you can write #ifndef RB_RESERVED_FD_P #define RB_RESERVED_FD_P(fd) 0 #endif for Ruby 1.9.2 or previous version to write compatible extensions. See [ruby-core:37727] * thread_win32.c (rb_reserved_fd_p): added (return 0 for any fds). * io.c (rb_io_initialize): raise ArgumentError if given fd is reserved by Ruby. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32394 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/io.c b/io.c
index 7900ab6638..e5372aa820 100644
--- a/io.c
+++ b/io.c
@@ -6517,6 +6517,9 @@ rb_io_initialize(int argc, VALUE *argv, VALUE io)
rb_io_extract_modeenc(&vmode, 0, opt, &oflags, &fmode, &convconfig);
fd = NUM2INT(fnum);
+ if (rb_reserved_fd_p(fd)) {
+ rb_raise(rb_eArgError, "The given fd is not accessible because RubyVM reserves it");
+ }
#if defined(HAVE_FCNTL) && defined(F_GETFL)
oflags = fcntl(fd, F_GETFL);
if (oflags == -1) rb_sys_fail(0);