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

ruby-changes:21515

From: akr <ko1@a...>
Date: Sun, 30 Oct 2011 10:02:56 +0900 (JST)
Subject: [ruby-changes:21515] akr:r33564 (trunk): * io.c (rb_cloexec_dup): don't allocate standard file descriptors.

akr	2011-10-30 10:02:46 +0900 (Sun, 30 Oct 2011)

  New Revision: 33564

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

  Log:
    * io.c (rb_cloexec_dup): don't allocate standard file descriptors.

  Modified files:
    trunk/ChangeLog
    trunk/io.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33563)
+++ ChangeLog	(revision 33564)
@@ -1,3 +1,7 @@
+Sun Oct 30 09:58:48 2011  Tanaka Akira  <akr@f...>
+
+	* io.c (rb_cloexec_dup): don't allocate standard file descriptors.
+
 Sun Oct 30 08:29:51 2011  Tanaka Akira  <akr@f...>
 
 	* io.c (rb_cloexec_dup2): don't set CLOEXEC for standard file
Index: io.c
===================================================================
--- io.c	(revision 33563)
+++ io.c	(revision 33564)
@@ -167,6 +167,7 @@
     if (flags == -1) {
         rb_bug("rb_fd_set_cloexec: fcntl(%d, F_GETFD) failed: %s", fd, strerror(errno));
     }
+    /* Don't set CLOEXEC for standard file descriptors: 0, 1, 2. */
     if (2 < fd) {
         if (!(flags & FD_CLOEXEC)) {
             flags |= FD_CLOEXEC;
@@ -206,10 +207,11 @@
 {
     int ret;
 
-#ifdef F_DUPFD_CLOEXEC
+#if defined(HAVE_FCNTL) && defined(F_DUPFD_CLOEXEC)
     static int try_fcntl = 1;
     if (try_fcntl) {
-        ret = fcntl(oldfd, F_DUPFD_CLOEXEC, 0);
+        /* don't allocate standard file descriptors: 0, 1, 2 */
+        ret = fcntl(oldfd, F_DUPFD_CLOEXEC, 3);
         /* F_DUPFD_CLOEXEC is available since Linux 2.6.24.  Linux 2.6.18 fails with EINVAL */
         if (ret == -1 && errno == EINVAL) {
             try_fcntl = 0;
@@ -219,6 +221,9 @@
     else {
         ret = dup(oldfd);
     }
+#elif defined(HAVE_FCNTL) && defined(F_DUPFD)
+    /* don't allocate standard file descriptors: 0, 1, 2 */
+    ret = fcntl(oldfd, F_DUPFD, 3);
 #else
     ret = dup(oldfd);
 #endif

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

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