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

ruby-changes:21506

From: akr <ko1@a...>
Date: Sat, 29 Oct 2011 20:59:55 +0900 (JST)
Subject: [ruby-changes:21506] akr:r33555 (trunk): * io.c (rb_cloexec_dup): use F_DUPFD_CLOEXEC if available.

akr	2011-10-29 20:59:46 +0900 (Sat, 29 Oct 2011)

  New Revision: 33555

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

  Log:
    * io.c (rb_cloexec_dup): use F_DUPFD_CLOEXEC if available.

  Modified files:
    trunk/ChangeLog
    trunk/io.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33554)
+++ ChangeLog	(revision 33555)
@@ -1,3 +1,7 @@
+Sat Oct 29 20:59:08 2011  Tanaka Akira  <akr@f...>
+
+	* io.c (rb_cloexec_dup): use F_DUPFD_CLOEXEC if available.
+
 Sat Oct 29 20:00:26 2011  Tanaka Akira  <akr@f...>
 
 	* include/ruby/intern.h (rb_cloexec_dup): declared.
Index: io.c
===================================================================
--- io.c	(revision 33554)
+++ io.c	(revision 33555)
@@ -205,7 +205,23 @@
 rb_cloexec_dup(int oldfd)
 {
     int ret;
+
+#ifdef F_DUPFD_CLOEXEC
+    static int try_fcntl = 1;
+    if (try_fcntl) {
+        ret = fcntl(oldfd, F_DUPFD_CLOEXEC, 0);
+        /* 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;
+            ret = dup(oldfd);
+        }
+    }
+    else {
+        ret = dup(oldfd);
+    }
+#else
     ret = dup(oldfd);
+#endif
     if (ret == -1) return -1;
     fd_set_cloexec(ret);
     return ret;

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

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