aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-29 22:48:41 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-29 22:48:41 +0000
commitcb9f3040d7020fcac74f292eba810081b73b195e (patch)
tree0dad7014a65294ba957ba08c5260369fc09a8f9e
parent71804183a368342b45e288bb2d6f7da8d69fd75f (diff)
downloadruby-cb9f3040d7020fcac74f292eba810081b73b195e.tar.gz
* configure.in: check dup3.
* io.c (rb_cloexec_dup2): use dup3 if available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33561 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--configure.in3
-rw-r--r--io.c15
3 files changed, 23 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 472195edf4..9e3f5806af 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sun Oct 30 07:47:10 2011 Tanaka Akira <akr@fsij.org>
+
+ * configure.in: check dup3.
+
+ * io.c (rb_cloexec_dup2): use dup3 if available.
+
Sat Oct 29 22:06:37 2011 Tanaka Akira <akr@fsij.org>
* include/ruby/intern.h (rb_cloexec_dup2): declared.
diff --git a/configure.in b/configure.in
index cd055da3d6..bf81905f0a 100644
--- a/configure.in
+++ b/configure.in
@@ -1351,7 +1351,8 @@ AC_CHECK_FUNCS(fmod killpg wait4 waitpid fork spawnv syscall __syscall chroot ge
setsid telldir seekdir fchmod cosh sinh tanh log2 round\
setuid setgid daemon select_large_fdset setenv unsetenv\
mktime timegm gmtime_r clock_gettime gettimeofday poll ppoll\
- pread sendfile shutdown sigaltstack dl_iterate_phdr)
+ pread sendfile shutdown sigaltstack dl_iterate_phdr\
+ dup3)
AC_CACHE_CHECK(for unsetenv returns a value, rb_cv_unsetenv_return_value,
[AC_TRY_COMPILE([
diff --git a/io.c b/io.c
index fadbb2ec90..5bec3622f4 100644
--- a/io.c
+++ b/io.c
@@ -232,7 +232,22 @@ rb_cloexec_dup2(int oldfd, int newfd)
{
int ret;
+#if defined(HAVE_DUP3) && defined(O_CLOEXEC)
+ static int try_dup3 = 1;
+ if (try_dup3) {
+ ret = dup3(oldfd, newfd, O_CLOEXEC);
+ /* dup3 is available since Linux 2.6.27. */
+ if (ret == -1 && errno == ENOSYS) {
+ try_dup3 = 0;
+ ret = dup2(oldfd, newfd);
+ }
+ }
+ else {
+ ret = dup2(oldfd, newfd);
+ }
+#else
ret = dup2(oldfd, newfd);
+#endif
if (ret == -1) return -1;
fd_set_cloexec(ret);
return ret;