[前][次][番号順一覧][スレッド一覧]

ruby-changes:6378

From: akr <ko1@a...>
Date: Sat, 5 Jul 2008 22:44:06 +0900 (JST)
Subject: [ruby-changes:6378] Ruby:r17894 (trunk): * io.c (rb_pipe_internal): new function for handling EMFILE and ENFILE

akr	2008-07-05 22:38:46 +0900 (Sat, 05 Jul 2008)

  New Revision: 17894

  Modified files:
    trunk/ChangeLog
    trunk/io.c

  Log:
    * io.c (rb_pipe_internal): new function for handling EMFILE and ENFILE
      error of pipe().
      (UPDATE_MAXFD_PIPE): removed.
      (pipe_open): use rb_pipe_internal.
      (rb_io_s_pipe): ditto.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=17894

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 17893)
+++ ChangeLog	(revision 17894)
@@ -1,3 +1,11 @@
+Sat Jul  5 22:37:00 2008  Tanaka Akira  <akr@f...>
+
+	* io.c (rb_pipe_internal): new function for handling EMFILE and ENFILE
+	  error of pipe().
+	  (UPDATE_MAXFD_PIPE): removed.
+	  (pipe_open): use rb_pipe_internal.
+	  (rb_io_s_pipe): ditto.
+
 Sat Jul  5 22:22:27 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* thread.c (thread_initialize): NUM2INT() returns int.
Index: io.c
===================================================================
--- io.c	(revision 17893)
+++ io.c	(revision 17894)
@@ -147,13 +147,7 @@
     do { \
         if (max_file_descriptor < (fd)) max_file_descriptor = (fd); \
     } while (0)
-#define UPDATE_MAXFD_PIPE(filedes) \
-    do { \
-        UPDATE_MAXFD((filedes)[0]); \
-        UPDATE_MAXFD((filedes)[1]); \
-    } while (0)
 
-
 #define argf_of(obj) (*(struct argf *)DATA_PTR(obj))
 #define ARGF argf_of(argf)
 
@@ -3644,6 +3638,24 @@
     rb_io_synchronized(fptr);
 }
 
+static int
+rb_pipe_internal(int *pipes)
+{
+    int ret;
+    ret = pipe(pipes);
+    if (ret == -1) {
+        if (errno == EMFILE || errno == ENFILE) {
+            rb_gc();
+            ret = pipe(pipes);
+        }
+    }
+    if (ret == 0) {
+        UPDATE_MAXFD(pipes[0]);
+        UPDATE_MAXFD(pipes[1]);
+    }
+    return ret;
+}
+
 #ifdef HAVE_FORK
 struct popen_arg {
     struct rb_exec_arg *execp;
@@ -3766,33 +3778,29 @@
     arg.write_pair[0] = arg.write_pair[1] = -1;
     switch (modef & (FMODE_READABLE|FMODE_WRITABLE)) {
       case FMODE_READABLE|FMODE_WRITABLE:
-        if (pipe(arg.write_pair) < 0)
+        if (rb_pipe_internal(arg.write_pair) < 0)
             rb_sys_fail(cmd);
-        UPDATE_MAXFD_PIPE(arg.write_pair);
-        if (pipe(arg.pair) < 0) {
+        if (rb_pipe_internal(arg.pair) < 0) {
             int e = errno;
             close(arg.write_pair[0]);
             close(arg.write_pair[1]);
             errno = e;
             rb_sys_fail(cmd);
         }
-        UPDATE_MAXFD_PIPE(arg.pair);
         if (eargp) {
             rb_exec_arg_addopt(eargp, INT2FIX(0), INT2FIX(arg.write_pair[0]));
             rb_exec_arg_addopt(eargp, INT2FIX(1), INT2FIX(arg.pair[1]));
         }
 	break;
       case FMODE_READABLE:
-        if (pipe(arg.pair) < 0)
+        if (rb_pipe_internal(arg.pair) < 0)
             rb_sys_fail(cmd);
-        UPDATE_MAXFD_PIPE(arg.pair);
         if (eargp)
             rb_exec_arg_addopt(eargp, INT2FIX(1), INT2FIX(arg.pair[1]));
 	break;
       case FMODE_WRITABLE:
-        if (pipe(arg.pair) < 0)
+        if (rb_pipe_internal(arg.pair) < 0)
             rb_sys_fail(cmd);
-        UPDATE_MAXFD_PIPE(arg.pair);
         if (eargp)
             rb_exec_arg_addopt(eargp, INT2FIX(0), INT2FIX(arg.pair[0]));
 	break;
@@ -6219,9 +6227,8 @@
     rb_io_t *fptr;
 
     rb_scan_args(argc, argv, "02", &v1, &v2);
-    if (pipe(pipes) == -1)
-	rb_sys_fail(0);
-    UPDATE_MAXFD_PIPE(pipes);
+    if (rb_pipe_internal(pipes) == -1)
+        rb_sys_fail(0);
 
     args[0] = klass;
     args[1] = INT2NUM(pipes[0]);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]