aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog19
-rw-r--r--include/ruby/intern.h2
-rw-r--r--io.c3
-rw-r--r--thread_pthread.c12
-rw-r--r--thread_win32.c5
5 files changed, 41 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index c1617bd6e7..b4a32c7461 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+Mon Jul 4 06:37:22 2011 Koichi Sasada <ko1@atdot.net>
+
+ * 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@yugui.jp>
* ext/extmk.rb (extmake): suppresses outputs from extconf.rb.
diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index c8b0e1af57..da1c036740 100644
--- a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -482,6 +482,8 @@ void rb_write_error(const char*);
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);
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);
diff --git a/thread_pthread.c b/thread_pthread.c
index 79b98a98c5..bde5d1cc77 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -1268,4 +1268,16 @@ ruby_stack_overflowed_p(const rb_thread_t *th, const void *addr)
}
#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 */
diff --git a/thread_win32.c b/thread_win32.c
index 68fb3467b8..873d37d7b5 100644
--- a/thread_win32.c
+++ b/thread_win32.c
@@ -779,4 +779,9 @@ ruby_alloca_chkstk(size_t len, void *sp)
}
}
#endif
+int
+rb_reserved_fd_p(int fd)
+{
+ return 0;
+}
#endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */