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

ruby-changes:20544

From: akr <ko1@a...>
Date: Thu, 21 Jul 2011 07:12:16 +0900 (JST)
Subject: [ruby-changes:20544] akr:r32591 (ruby_1_9_3): * backport r32579, r32581, r32587 by akr and r32588 by kazu.

akr	2011-07-21 07:11:56 +0900 (Thu, 21 Jul 2011)

  New Revision: 32591

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

  Log:
    * backport r32579, r32581, r32587 by akr and r32588 by kazu.
    
    r32579:
    
    * io.c (rb_update_max_fd): new function.
    
    * internal.h (rb_update_max_fd): declare rb_update_max_fd.
    
    * thread_pthread.c (rb_thread_create_timer_thread): update max fd when
      timer thread pipe is created.
    
    r32581:
    
    * io.c (UPDATE_MAXFD): removed.
    
    r32587:
    
    * include/ruby/intern.h (rb_update_max_fd): declaration moved from
      internal.h.
    
    * file.c: ditto.
    
    * io.c: call rb_update_max_fd for each new fds.
    
    * process.c: ditto.
    
    * random.c: ditto.
    
    * ruby.c: ditto.
    
    * ext/io/console/console.c: ditto.
    
    * ext/openssl/ossl_bio.c: ditto.
    
    * ext/pty/pty.c: ditto.
    
    * ext/socket/init.c: ditto.
    
    * ext/socket/socket.c: ditto.
    
    * ext/socket/ancdata.c: ditto.
    
    * ext/socket/unixsocket.c: ditto.
    
    r32588:
    
    * io.c (rb_update_max_fd): remove parentheses. they are not in
      macro.

  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/ext/io/console/console.c
    branches/ruby_1_9_3/ext/openssl/ossl_bio.c
    branches/ruby_1_9_3/ext/pty/pty.c
    branches/ruby_1_9_3/ext/socket/ancdata.c
    branches/ruby_1_9_3/ext/socket/init.c
    branches/ruby_1_9_3/ext/socket/socket.c
    branches/ruby_1_9_3/ext/socket/unixsocket.c
    branches/ruby_1_9_3/file.c
    branches/ruby_1_9_3/include/ruby/intern.h
    branches/ruby_1_9_3/io.c
    branches/ruby_1_9_3/process.c
    branches/ruby_1_9_3/random.c
    branches/ruby_1_9_3/ruby.c
    branches/ruby_1_9_3/thread_pthread.c

Index: ruby_1_9_3/include/ruby/intern.h
===================================================================
--- ruby_1_9_3/include/ruby/intern.h	(revision 32590)
+++ ruby_1_9_3/include/ruby/intern.h	(revision 32591)
@@ -484,6 +484,7 @@
 int rb_pipe(int *pipes);
 int rb_reserved_fd_p(int fd);
 #define RB_RESERVED_FD_P(fd) rb_reserved_fd_p(fd)
+void rb_update_max_fd(int fd);
 /* marshal.c */
 VALUE rb_marshal_dump(VALUE, VALUE);
 VALUE rb_marshal_load(VALUE);
Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 32590)
+++ ruby_1_9_3/ChangeLog	(revision 32591)
@@ -1,3 +1,54 @@
+Thu Jul 21 07:07:57 2011  Tanaka Akira  <akr@f...>
+
+	* backport r32579, r32581, r32587 by akr and r32588 by kazu.
+
+	r32579:
+
+	* io.c (rb_update_max_fd): new function.
+
+	* internal.h (rb_update_max_fd): declare rb_update_max_fd.
+
+	* thread_pthread.c (rb_thread_create_timer_thread): update max fd when
+	  timer thread pipe is created.
+
+	r32581:
+
+	* io.c (UPDATE_MAXFD): removed.
+
+	r32587:
+
+	* include/ruby/intern.h (rb_update_max_fd): declaration moved from
+	  internal.h.
+
+	* file.c: ditto.
+
+	* io.c: call rb_update_max_fd for each new fds.
+
+	* process.c: ditto.
+
+	* random.c: ditto.
+
+	* ruby.c: ditto.
+
+	* ext/io/console/console.c: ditto.
+
+	* ext/openssl/ossl_bio.c: ditto.
+
+	* ext/pty/pty.c: ditto.
+
+	* ext/socket/init.c: ditto.
+
+	* ext/socket/socket.c: ditto.
+
+	* ext/socket/ancdata.c: ditto.
+
+	* ext/socket/unixsocket.c: ditto.
+
+	r32588:
+
+	* io.c (rb_update_max_fd): remove parentheses. they are not in
+	  macro.
+
 Sun Jul 17 08:07:31 2011  Martin Bosslet  <Martin.Bosslet@g...>
 
 	* backport r32563 from trunk
Index: ruby_1_9_3/thread_pthread.c
===================================================================
--- ruby_1_9_3/thread_pthread.c	(revision 32590)
+++ ruby_1_9_3/thread_pthread.c	(revision 32591)
@@ -1193,6 +1193,8 @@
 	    if (err != 0) {
 		rb_bug_errno("thread_timer: Failed to create communication pipe for timer thread", errno);
 	    }
+            rb_update_max_fd(timer_thread_pipe[0]);
+            rb_update_max_fd(timer_thread_pipe[1]);
 #if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(F_SETFL)
 	    {
 		int oflags;
Index: ruby_1_9_3/io.c
===================================================================
--- ruby_1_9_3/io.c	(revision 32590)
+++ ruby_1_9_3/io.c	(revision 32591)
@@ -151,10 +151,11 @@
 };
 
 static int max_file_descriptor = NOFILE;
-#define UPDATE_MAXFD(fd) \
-    do { \
-        if (max_file_descriptor < (fd)) max_file_descriptor = (fd); \
-    } while (0)
+void
+rb_update_max_fd(int fd)
+{
+    if (max_file_descriptor < fd) max_file_descriptor = fd;
+}
 
 #define argf_of(obj) (*(struct argf *)DATA_PTR(obj))
 #define ARGF argf_of(argf)
@@ -526,7 +527,7 @@
 	    rb_sys_fail(0);
 	}
     }
-    UPDATE_MAXFD(fd);
+    rb_update_max_fd(fd);
     return fd;
 }
 
@@ -4591,7 +4592,11 @@
 static inline int
 rb_sysopen_internal(struct sysopen_struct *data)
 {
-    return (int)rb_thread_blocking_region(sysopen_func, data, RUBY_UBF_IO, 0);
+    int fd;
+    fd = (int)rb_thread_blocking_region(sysopen_func, data, RUBY_UBF_IO, 0);
+    if (0 <= fd)
+        rb_update_max_fd(fd);
+    return fd;
 }
 
 static int
@@ -4617,7 +4622,7 @@
 	    rb_sys_fail(RSTRING_PTR(fname));
 	}
     }
-    UPDATE_MAXFD(fd);
+    rb_update_max_fd(fd);
     return fd;
 }
 
@@ -4910,8 +4915,8 @@
         }
     }
     if (ret == 0) {
-        UPDATE_MAXFD(pipes[0]);
-        UPDATE_MAXFD(pipes[1]);
+        rb_update_max_fd(pipes[0]);
+        rb_update_max_fd(pipes[1]);
     }
     return ret;
 }
@@ -5793,6 +5798,7 @@
 	    /* need to keep FILE objects of stdin, stdout and stderr */
 	    if (dup2(fd2, fd) < 0)
 		rb_sys_fail_path(orig->pathv);
+            rb_update_max_fd(fd);
 	}
 	else {
             fclose(fptr->stdio_file);
@@ -5800,6 +5806,7 @@
             fptr->fd = -1;
             if (dup2(fd2, fd) < 0)
                 rb_sys_fail_path(orig->pathv);
+            rb_update_max_fd(fd);
             fptr->fd = fd;
 	}
 	rb_thread_fd_close(fd);
@@ -6383,6 +6390,7 @@
     fp->mode = fmode;
     io_check_tty(fp);
     if (path) fp->pathv = rb_obj_freeze(rb_str_new_cstr(path));
+    rb_update_max_fd(fd);
 
     return io;
 }
@@ -6535,7 +6543,7 @@
 #else
     if (fstat(fd, &st) == -1) rb_sys_fail(0);
 #endif
-    UPDATE_MAXFD(fd);
+    rb_update_max_fd(fd);
 #if defined(HAVE_FCNTL) && defined(F_GETFL)
     ofmode = rb_io_oflags_fmode(oflags);
     if (NIL_P(vmode)) {
@@ -7690,7 +7698,7 @@
     retval = (int)rb_thread_io_blocking_region(nogvl_io_cntl, &arg, fd);
 #if defined(F_DUPFD)
     if (!io_p && retval != -1 && cmd == F_DUPFD) {
-	UPDATE_MAXFD(retval);
+	rb_update_max_fd(retval);
     }
 #endif
 
Index: ruby_1_9_3/process.c
===================================================================
--- ruby_1_9_3/process.c	(revision 32590)
+++ ruby_1_9_3/process.c	(revision 32591)
@@ -1961,6 +1961,7 @@
             ERRMSG("dup");
             return -1;
         }
+        rb_update_max_fd(save_fd);
         newary = rb_ary_entry(save, EXEC_OPTION_DUP2);
         if (NIL_P(newary)) {
             newary = hide_obj(rb_ary_new());
@@ -2077,6 +2078,7 @@
                 ERRMSG("dup2");
                 goto fail;
             }
+            rb_update_max_fd(pairs[j].newfd);
             pairs[j].oldfd = -1;
             j = pairs[j].older_index;
             if (j != -1)
@@ -2115,6 +2117,7 @@
                 ERRMSG("dup");
                 goto fail;
             }
+            rb_update_max_fd(extra_fd);
         }
         else {
             ret = redirect_dup2(pairs[i].oldfd, extra_fd);
@@ -2122,6 +2125,7 @@
                 ERRMSG("dup2");
                 goto fail;
             }
+            rb_update_max_fd(extra_fd);
         }
         pairs[i].oldfd = extra_fd;
         j = pairs[i].older_index;
@@ -2132,6 +2136,7 @@
                 ERRMSG("dup2");
                 goto fail;
             }
+            rb_update_max_fd(ret);
             pairs[j].oldfd = -1;
             j = pairs[j].older_index;
         }
@@ -2189,6 +2194,7 @@
             ERRMSG("open");
             return -1;
         }
+        rb_update_max_fd(fd2);
         while (i < RARRAY_LEN(ary) &&
                (elt = RARRAY_PTR(ary)[i], RARRAY_PTR(elt)[1] == param)) {
             fd = FIX2INT(RARRAY_PTR(elt)[0]);
@@ -2203,6 +2209,7 @@
                     ERRMSG("dup2");
                     return -1;
                 }
+                rb_update_max_fd(fd);
             }
             i++;
         }
@@ -2235,6 +2242,7 @@
             ERRMSG("dup2");
             return -1;
         }
+        rb_update_max_fd(newfd);
     }
     return 0;
 }
@@ -2501,6 +2509,7 @@
             ret = fcntl(fdp[i], F_DUPFD, min);
             if (ret == -1)
                 return -1;
+            rb_update_max_fd(ret);
             close(fdp[i]);
             fdp[i] = ret;
         }
@@ -3583,6 +3592,7 @@
     if (ret == -1) return -1;
 
     if ((fd = open("/dev/tty", O_RDWR)) >= 0) {
+        rb_update_max_fd(fd);
 	ioctl(fd, TIOCNOTTY, NULL);
 	close(fd);
     }
@@ -4873,6 +4883,7 @@
 	err = chdir("/");
 
     if (!noclose && (n = open("/dev/null", O_RDWR, 0)) != -1) {
+        rb_update_max_fd(n);
 	(void)dup2(n, 0);
 	(void)dup2(n, 1);
 	(void)dup2(n, 2);
Index: ruby_1_9_3/ext/pty/pty.c
===================================================================
--- ruby_1_9_3/ext/pty/pty.c	(revision 32590)
+++ ruby_1_9_3/ext/pty/pty.c	(revision 32591)
@@ -177,6 +177,7 @@
     {
         int i = open("/dev/tty", O_RDONLY);
         if (i < 0) ERROR_EXIT("/dev/tty");
+        rb_update_max_fd(i);
         if (ioctl(i, TIOCNOTTY, (char *)0))
             ERROR_EXIT("ioctl(TIOCNOTTY)");
         close(i);
@@ -198,6 +199,7 @@
     if (slave < 0) {
         ERROR_EXIT("open: pty slave");
     }
+    rb_update_max_fd(slave);
     close(master);
 #endif
     dup2(slave,0);
@@ -289,6 +291,7 @@
     sigemptyset(&dfl.sa_mask);
 
     if ((masterfd = posix_openpt(O_RDWR|O_NOCTTY)) == -1) goto error;
+    rb_update_max_fd(masterfd);
     if (sigaction(SIGCHLD, &dfl, &old) == -1) goto error;
     if (grantpt(masterfd) == -1) goto grantpt_error;
     if (sigaction(SIGCHLD, &old, NULL) == -1) goto error;
@@ -296,6 +299,7 @@
     if ((slavedevice = ptsname(masterfd)) == NULL) goto error;
     if (no_mesg(slavedevice, nomesg) == -1) goto error;
     if ((slavefd = open(slavedevice, O_RDWR|O_NOCTTY, 0)) == -1) goto error;
+    rb_update_max_fd(slavefd);
 
 #if defined I_PUSH && !defined linux
     if (ioctl(slavefd, I_PUSH, "ptem") == -1) goto error;
@@ -327,6 +331,8 @@
 	if (!fail) return -1;
 	rb_raise(rb_eRuntimeError, "openpty() failed");
     }
+    rb_update_max_fd(*master);
+    rb_update_max_fd(*slave);
     if (no_mesg(SlaveName, nomesg) == -1) {
 	if (!fail) return -1;
 	rb_raise(rb_eRuntimeError, "can't chmod slave pty");
@@ -342,8 +348,11 @@
 	if (!fail) return -1;
 	rb_raise(rb_eRuntimeError, "_getpty() failed");
     }
+    rb_update_max_fd(*master);
 
     *slave = open(name, O_RDWR);
+    /* error check? */
+    rb_update_max_fd(*slave);
     strlcpy(SlaveName, name, DEVICELEN);
 
     return 0;
@@ -357,6 +366,7 @@
     extern int grantpt(int);
 
     if((masterfd = open("/dev/ptmx", O_RDWR, 0)) == -1) goto error;
+    rb_update_max_fd(masterfd);
     s = signal(SIGCHLD, SIG_DFL);
     if(grantpt(masterfd) == -1) goto error;
     signal(SIGCHLD, s);
@@ -364,6 +374,7 @@
     if((slavedevice = ptsname(masterfd)) == NULL) goto error;
     if (no_mesg(slavedevice, nomesg) == -1) goto error;
     if((slavefd = open(slavedevice, O_RDWR, 0)) == -1) goto error;
+    rb_update_max_fd(slavefd);
 #if defined I_PUSH && !defined linux
     if(ioctl(slavefd, I_PUSH, "ptem") == -1) goto error;
     if(ioctl(slavefd, I_PUSH, "ldterm") == -1) goto error;
@@ -387,9 +398,11 @@
     for (p = deviceNo; *p != NULL; p++) {
 	snprintf(MasterName, sizeof MasterName, MasterDevice, *p);
 	if ((masterfd = open(MasterName,O_RDWR,0)) >= 0) {
+            rb_update_max_fd(masterfd);
 	    *master = masterfd;
 	    snprintf(SlaveName, DEVICELEN, SlaveDevice, *p);
 	    if ((slavefd = open(SlaveName,O_RDWR,0)) >= 0) {
+                rb_update_max_fd(slavefd);
 		*slave = slavefd;
 		if (chown(SlaveName, getuid(), getgid()) != 0) goto error;
 		if (chmod(SlaveName, nomesg ? 0600 : 0622) != 0) goto error;
@@ -577,6 +590,7 @@
     wfptr->fd = dup(info.fd);
     if (wfptr->fd == -1)
         rb_sys_fail("dup()");
+    rb_update_max_fd(wfptr->fd);
     wfptr->pathv = rfptr->pathv;
 
     res = rb_ary_new2(3);
Index: ruby_1_9_3/ext/openssl/ossl_bio.c
===================================================================
--- ruby_1_9_3/ext/openssl/ossl_bio.c	(revision 32590)
+++ ruby_1_9_3/ext/openssl/ossl_bio.c	(revision 32591)
@@ -28,6 +28,7 @@
 	if ((fd = dup(FPTR_TO_FD(fptr))) < 0){
 	    rb_sys_fail(0);
 	}
+        rb_update_max_fd(fd);
 	if (!(fp = fdopen(fd, "r"))){
 	    close(fd);
 	    rb_sys_fail(0);
Index: ruby_1_9_3/ext/socket/init.c
===================================================================
--- ruby_1_9_3/ext/socket/init.c	(revision 32590)
+++ ruby_1_9_3/ext/socket/init.c	(revision 32591)
@@ -48,6 +48,7 @@
 
     if (fstat(fd, &sbuf) < 0)
         rb_sys_fail(0);
+    rb_update_max_fd(fd);
     if (!S_ISSOCK(sbuf.st_mode))
         rb_raise(rb_eArgError, "not a socket file descriptor");
 #else
@@ -250,6 +251,8 @@
 	    fd = socket(domain, type, proto);
 	}
     }
+    if (0 <= fd)
+        rb_update_max_fd(fd);
     return fd;
 }
 
@@ -463,6 +466,7 @@
 	}
         rb_sys_fail("accept(2)");
     }
+    rb_update_max_fd(fd2);
     make_fd_nonblock(fd2);
     return rsock_init_sock(rb_obj_alloc(klass), fd2);
 }
@@ -509,6 +513,7 @@
 	}
 	rb_sys_fail(0);
     }
+    rb_update_max_fd(fd2);
     if (!klass) return INT2NUM(fd2);
     return rsock_init_sock(rb_obj_alloc(klass), fd2);
 }
Index: ruby_1_9_3/ext/socket/socket.c
===================================================================
--- ruby_1_9_3/ext/socket/socket.c	(revision 32590)
+++ ruby_1_9_3/ext/socket/socket.c	(revision 32591)
@@ -119,6 +119,8 @@
     if (ret < 0) {
 	rb_sys_fail("socketpair(2)");
     }
+    rb_update_max_fd(sp[0]);
+    rb_update_max_fd(sp[1]);
 
     s1 = rsock_init_sock(rb_obj_alloc(klass), sp[0]);
     s2 = rsock_init_sock(rb_obj_alloc(klass), sp[1]);
Index: ruby_1_9_3/ext/socket/ancdata.c
===================================================================
--- ruby_1_9_3/ext/socket/ancdata.c	(revision 32590)
+++ ruby_1_9_3/ext/socket/ancdata.c	(revision 32591)
@@ -1384,6 +1384,7 @@
         int *end = (int *)((char *)cmh + cmh->cmsg_len);
         while ((char *)fdp + sizeof(int) <= (char *)end &&
                (char *)fdp + sizeof(int) <= msg_end) {
+            rb_update_max_fd(*fdp);
             close(*fdp);
             fdp++;
         }
@@ -1426,6 +1427,7 @@
             VALUE io;
             if (fstat(fd, &stbuf) == -1)
                 rb_raise(rb_eSocket, "invalid fd in SCM_RIGHTS");
+            rb_update_max_fd(fd);
             if (S_ISSOCK(stbuf.st_mode))
                 io = rsock_init_sock(rb_obj_alloc(rb_cSocket), fd);
             else
Index: ruby_1_9_3/ext/socket/unixsocket.c
===================================================================
--- ruby_1_9_3/ext/socket/unixsocket.c	(revision 32590)
+++ ruby_1_9_3/ext/socket/unixsocket.c	(revision 32591)
@@ -383,6 +383,7 @@
 #if FD_PASSING_BY_MSG_CONTROL
     memcpy(&fd, CMSG_DATA(&cmsg.hdr), sizeof(int));
 #endif
+    rb_update_max_fd(fd);
 
     if (klass == Qnil)
 	return INT2FIX(fd);
Index: ruby_1_9_3/ext/io/console/console.c
===================================================================
--- ruby_1_9_3/ext/io/console/console.c	(revision 32590)
+++ ruby_1_9_3/ext/io/console/console.c	(revision 32591)
@@ -562,6 +562,7 @@
 #ifdef CONSOLE_DEVICE_FOR_WRITING
 	fd = open(CONSOLE_DEVICE_FOR_WRITING, O_WRONLY);
 	if (fd < 0) return Qnil;
+        rb_update_max_fd(fd);
 	args[1] = INT2FIX(O_WRONLY);
 	args[0] = INT2NUM(fd);
 	out = rb_class_new_instance(2, args, klass);
@@ -573,6 +574,7 @@
 #endif
 	    return Qnil;
 	}
+        rb_update_max_fd(fd);
 	args[1] = INT2FIX(O_RDWR);
 	args[0] = INT2NUM(fd);
 	con = rb_class_new_instance(2, args, klass);
Index: ruby_1_9_3/ruby.c
===================================================================
--- ruby_1_9_3/ruby.c	(revision 32590)
+++ ruby_1_9_3/ruby.c	(revision 32591)
@@ -1527,6 +1527,7 @@
 	if ((fd = open(fname, mode)) < 0) {
 	    rb_load_fail(fname);
 	}
+        rb_update_max_fd(fd);
 
 	f = rb_io_fdopen(fd, mode, fname);
     }
Index: ruby_1_9_3/file.c
===================================================================
--- ruby_1_9_3/file.c	(revision 32590)
+++ ruby_1_9_3/file.c	(revision 32591)
@@ -3914,6 +3914,7 @@
 	if ((tmpfd = open(StringValueCStr(path), 0)) < 0) {
 	    rb_sys_fail(RSTRING_PTR(path));
 	}
+        rb_update_max_fd(tmpfd);
 	if (chsize(tmpfd, pos) < 0) {
 	    close(tmpfd);
 	    rb_sys_fail(RSTRING_PTR(path));
@@ -5061,6 +5062,7 @@
     int ret = 1;
     int fd = open(path, O_RDONLY);
     if (fd == -1) return 0;
+    rb_update_max_fd(fd);
 #if !defined DOSISH
     {
 	struct stat st;
Index: ruby_1_9_3/random.c
===================================================================
--- ruby_1_9_3/random.c	(revision 32590)
+++ ruby_1_9_3/random.c	(revision 32591)
@@ -512,6 +512,7 @@
             |O_NOCTTY
 #endif
             )) >= 0) {
+        rb_update_max_fd(fd);
         if (fstat(fd, &statbuf) == 0 && S_ISCHR(statbuf.st_mode)) {
 	    if (read(fd, seed, DEFAULT_SEED_LEN) < DEFAULT_SEED_LEN) {
 		/* abandon */;

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

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