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

ruby-changes:21504

From: akr <ko1@a...>
Date: Sat, 29 Oct 2011 20:02:45 +0900 (JST)
Subject: [ruby-changes:21504] akr:r33553 (trunk): * include/ruby/intern.h (rb_cloexec_dup): declared.

akr	2011-10-29 20:02:32 +0900 (Sat, 29 Oct 2011)

  New Revision: 33553

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

  Log:
    * include/ruby/intern.h (rb_cloexec_dup): declared.
    
    * io.c (rb_cloexec_dup): new function.
      (ruby_dup): use rb_cloexec_dup.
    
    * ext/pty/pty.c (pty_getpty): use rb_cloexec_dup.
      
    * ext/openssl/ossl_bio.c (ossl_obj2bio): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/ext/openssl/ossl_bio.c
    trunk/ext/pty/pty.c
    trunk/include/ruby/intern.h
    trunk/io.c

Index: include/ruby/intern.h
===================================================================
--- include/ruby/intern.h	(revision 33552)
+++ include/ruby/intern.h	(revision 33553)
@@ -503,6 +503,7 @@
 int rb_pipe(int *pipes);
 int rb_reserved_fd_p(int fd);
 int rb_cloexec_open(const char *pathname, int flags, mode_t mode);
+int rb_cloexec_dup(int oldfd);
 #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 33552)
+++ ChangeLog	(revision 33553)
@@ -1,3 +1,14 @@
+Sat Oct 29 20:00:26 2011  Tanaka Akira  <akr@f...>
+
+	* include/ruby/intern.h (rb_cloexec_dup): declared.
+
+	* io.c (rb_cloexec_dup): new function.
+	  (ruby_dup): use rb_cloexec_dup.
+
+	* ext/pty/pty.c (pty_getpty): use rb_cloexec_dup.
+	  
+	* ext/openssl/ossl_bio.c (ossl_obj2bio): ditto.
+
 Sat Oct 29 16:11:34 2011  Tanaka Akira  <akr@f...>
 
 	* ext/sdbm/_sdbm.c (sdbm_prep): use O_CLOEXEC if available.
Index: io.c
===================================================================
--- io.c	(revision 33552)
+++ io.c	(revision 33553)
@@ -200,6 +200,15 @@
     return ret;
 }
 
+int
+rb_cloexec_dup(int oldfd)
+{
+    int ret;
+    ret = dup(oldfd);
+    if (ret == -1) return -1;
+    fd_set_cloexec(ret);
+    return ret;
+}
 
 #define argf_of(obj) (*(struct argf *)DATA_PTR(obj))
 #define ARGF argf_of(argf)
@@ -561,17 +570,17 @@
 {
     int fd;
 
-    fd = dup(orig);
+    fd = rb_cloexec_dup(orig);
     if (fd < 0) {
 	if (errno == EMFILE || errno == ENFILE || errno == ENOMEM) {
 	    rb_gc();
-	    fd = dup(orig);
+	    fd = rb_cloexec_dup(orig);
 	}
 	if (fd < 0) {
 	    rb_sys_fail(0);
 	}
     }
-    rb_fd_set_cloexec(fd);
+    rb_update_max_fd(fd);
     return fd;
 }
 
Index: ext/pty/pty.c
===================================================================
--- ext/pty/pty.c	(revision 33552)
+++ ext/pty/pty.c	(revision 33553)
@@ -603,10 +603,10 @@
     rfptr->pathv = rb_obj_freeze(rb_str_new_cstr(SlaveName));
 
     wfptr->mode = rb_io_mode_flags("w") | FMODE_SYNC;
-    wfptr->fd = dup(info.fd);
+    wfptr->fd = rb_cloexec_dup(info.fd);
     if (wfptr->fd == -1)
         rb_sys_fail("dup()");
-    rb_fd_set_cloexec(wfptr->fd);
+    rb_update_max_fd(wfptr->fd);
     wfptr->pathv = rfptr->pathv;
 
     res = rb_ary_new2(3);
Index: ext/openssl/ossl_bio.c
===================================================================
--- ext/openssl/ossl_bio.c	(revision 33552)
+++ ext/openssl/ossl_bio.c	(revision 33553)
@@ -25,10 +25,10 @@
 
 	GetOpenFile(obj, fptr);
 	rb_io_check_readable(fptr);
-	if ((fd = dup(FPTR_TO_FD(fptr))) < 0){
+	if ((fd = rb_cloexec_dup(FPTR_TO_FD(fptr))) < 0){
 	    rb_sys_fail(0);
 	}
-        rb_fd_set_cloexec(fd);
+        rb_update_max_fd(fd);
 	if (!(fp = fdopen(fd, "r"))){
 	    close(fd);
 	    rb_sys_fail(0);

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

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