ruby-changes:20346
From: ko1 <ko1@a...>
Date: Mon, 4 Jul 2011 06:57:14 +0900 (JST)
Subject: [ruby-changes:20346] ko1:r32394 (trunk): * include/ruby/intern.h, thread_pthread.c (rb_reserved_fd_p,
ko1 2011-07-04 06:56:59 +0900 (Mon, 04 Jul 2011) New Revision: 32394 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32394 Log: * 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. Modified files: trunk/ChangeLog trunk/include/ruby/intern.h trunk/io.c trunk/thread_pthread.c trunk/thread_win32.c Index: thread_win32.c =================================================================== --- thread_win32.c (revision 32393) +++ thread_win32.c (revision 32394) @@ -779,4 +779,9 @@ } } #endif +int +rb_reserved_fd_p(int fd) +{ + return 0; +} #endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */ Index: include/ruby/intern.h =================================================================== --- include/ruby/intern.h (revision 32393) +++ include/ruby/intern.h (revision 32394) @@ -482,6 +482,8 @@ 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); +#define RB_RESERVED_FD_P(fd) rb_reserved_fd_p(fd) /* marshal.c */ VALUE rb_marshal_dump(VALUE, VALUE); VALUE rb_marshal_load(VALUE); Index: ChangeLog =================================================================== --- ChangeLog (revision 32393) +++ ChangeLog (revision 32394) @@ -1,3 +1,22 @@ +Mon Jul 4 06:37:22 2011 Koichi Sasada <ko1@a...> + + * 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. + Sun Jul 3 23:43:56 2011 Yuki Sonoda (Yugui) <yugui@y...> * ext/extmk.rb (extmake): suppresses outputs from extconf.rb. Index: thread_pthread.c =================================================================== --- thread_pthread.c (revision 32393) +++ thread_pthread.c (revision 32394) @@ -1268,4 +1268,16 @@ } #endif +int +rb_reserved_fd_p(int fd) +{ + if (fd == timer_thread_pipe[0] || + fd == timer_thread_pipe[1]) { + return 1; + } + else { + return 0; + } +} + #endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */ Index: io.c =================================================================== --- io.c (revision 32393) +++ io.c (revision 32394) @@ -6517,6 +6517,9 @@ 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); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/