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

ruby-changes:21523

From: akr <ko1@a...>
Date: Sun, 30 Oct 2011 21:13:16 +0900 (JST)
Subject: [ruby-changes:21523] akr:r33572 (trunk): * include/ruby/intern.h (rb_cloexec_pipe): declared.

akr	2011-10-30 21:13:05 +0900 (Sun, 30 Oct 2011)

  New Revision: 33572

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

  Log:
    * include/ruby/intern.h (rb_cloexec_pipe): declared.
    
    * io.c (rb_cloexec_pipe): new function.
      (rb_pipe): use rb_cloexec_pipe.
    
    * thread_pthread.c (rb_thread_create_timer_thread): use
      rb_cloexec_pipe.

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/intern.h
    trunk/io.c
    trunk/thread_pthread.c

Index: include/ruby/intern.h
===================================================================
--- include/ruby/intern.h	(revision 33571)
+++ include/ruby/intern.h	(revision 33572)
@@ -505,6 +505,7 @@
 int rb_cloexec_open(const char *pathname, int flags, mode_t mode);
 int rb_cloexec_dup(int oldfd);
 int rb_cloexec_dup2(int oldfd, int newfd);
+int rb_cloexec_pipe(int fildes[2]);
 #define RB_RESERVED_FD_P(fd) rb_reserved_fd_p(fd)
 void rb_update_max_fd(int fd);
 void rb_fd_set_cloexec(int fd);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33571)
+++ ChangeLog	(revision 33572)
@@ -1,3 +1,13 @@
+Sun Oct 30 21:12:47 2011  Tanaka Akira  <akr@f...>
+
+	* include/ruby/intern.h (rb_cloexec_pipe): declared.
+
+	* io.c (rb_cloexec_pipe): new function.
+	  (rb_pipe): use rb_cloexec_pipe.
+
+	* thread_pthread.c (rb_thread_create_timer_thread): use
+	  rb_cloexec_pipe.
+
 Sun Oct 30 20:06:07 2011  Tanaka Akira  <akr@f...>
 
 	* io.c (rb_cloexec_dup): refine control flow.
Index: thread_pthread.c
===================================================================
--- thread_pthread.c	(revision 33571)
+++ thread_pthread.c	(revision 33572)
@@ -1210,12 +1210,12 @@
 		close_communication_pipe();
 	    }
 
-	    err = pipe(timer_thread_pipe);
+	    err = rb_cloexec_pipe(timer_thread_pipe);
 	    if (err != 0) {
 		rb_bug_errno("thread_timer: Failed to create communication pipe for timer thread", errno);
 	    }
-            rb_fd_set_cloexec(timer_thread_pipe[0]);
-            rb_fd_set_cloexec(timer_thread_pipe[1]);
+            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;
@@ -1224,12 +1224,6 @@
 		oflags |= O_NONBLOCK;
 		fcntl(timer_thread_pipe[1], F_SETFL, oflags);
 #endif /* defined(O_NONBLOCK) */
-#if defined(FD_CLOEXEC)
-		oflags = fcntl(timer_thread_pipe[0], F_GETFD);
-		fcntl(timer_thread_pipe[0], F_SETFD, oflags | FD_CLOEXEC);
-		oflags = fcntl(timer_thread_pipe[1], F_GETFD);
-		fcntl(timer_thread_pipe[1], F_SETFD, oflags | FD_CLOEXEC);
-#endif /* defined(FD_CLOEXEC) */
 	    }
 #endif /* defined(HAVE_FCNTL) && defined(F_GETFL) && defined(F_SETFL) */
 
Index: io.c
===================================================================
--- io.c	(revision 33571)
+++ io.c	(revision 33572)
@@ -262,6 +262,25 @@
     return ret;
 }
 
+int
+rb_cloexec_pipe(int fildes[2])
+{
+    int ret;
+    ret = pipe(fildes);
+    if (ret == -1) return -1;
+#ifdef __CYGWIN__
+    if (ret == 0 && fildes[1] == -1) {
+	close(fildes[0]);
+	fildes[0] = -1;
+	errno = ENFILE;
+	return -1;
+    }
+#endif
+    fd_set_cloexec(fildes[0]);
+    fd_set_cloexec(fildes[1]);
+    return ret;
+}
+
 #define argf_of(obj) (*(struct argf *)DATA_PTR(obj))
 #define ARGF argf_of(argf)
 
@@ -5008,24 +5027,16 @@
 rb_pipe(int *pipes)
 {
     int ret;
-    ret = pipe(pipes);
+    ret = rb_cloexec_pipe(pipes);
     if (ret == -1) {
         if (errno == EMFILE || errno == ENFILE) {
             rb_gc();
-            ret = pipe(pipes);
+            ret = rb_cloexec_pipe(pipes);
         }
     }
-#ifdef __CYGWIN__
-    if (ret == 0 && pipes[1] == -1) {
-	close(pipes[0]);
-	pipes[0] = -1;
-	errno = ENFILE;
-	return -1;
-    }
-#endif
     if (ret == 0) {
-        rb_fd_set_cloexec(pipes[0]);
-        rb_fd_set_cloexec(pipes[1]);
+        rb_update_max_fd(pipes[0]);
+        rb_update_max_fd(pipes[1]);
     }
     return ret;
 }

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

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