aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-30 13:48:35 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-30 13:48:35 +0000
commite7f8c03818873b7cd64cb5080fe329098352af6c (patch)
tree216672d258660b66cfa9e9d3fd8a6c38460acb5a
parenta3efca16a12044b46f0e305ddcacfe6d412afcca (diff)
downloadruby-e7f8c03818873b7cd64cb5080fe329098352af6c.tar.gz
* configure.in: check pipe2.
* io.c (rb_cloexec_pipe): use pipe2 if available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33574 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--configure.in2
-rw-r--r--io.c18
3 files changed, 25 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 980e5e8631..6ca2f49c90 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sun Oct 30 22:46:46 2011 Tanaka Akira <akr@fsij.org>
+
+ * configure.in: check pipe2.
+
+ * io.c (rb_cloexec_pipe): use pipe2 if available.
+
Sun Oct 30 22:32:44 2011 Tanaka Akira <akr@fsij.org>
* ruby.c (fill_standard_fds): use fstat() instead of fcntl(F_GETFD)
diff --git a/configure.in b/configure.in
index bf81905f0a..530301222c 100644
--- a/configure.in
+++ b/configure.in
@@ -1352,7 +1352,7 @@ AC_CHECK_FUNCS(fmod killpg wait4 waitpid fork spawnv syscall __syscall chroot ge
setuid setgid daemon select_large_fdset setenv unsetenv\
mktime timegm gmtime_r clock_gettime gettimeofday poll ppoll\
pread sendfile shutdown sigaltstack dl_iterate_phdr\
- dup3)
+ dup3 pipe2)
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 33b7382ab4..2fb9ee5b63 100644
--- a/io.c
+++ b/io.c
@@ -266,7 +266,25 @@ int
rb_cloexec_pipe(int fildes[2])
{
int ret;
+
+#if defined(HAVE_PIPE2)
+ static int try_pipe2 = 1;
+ if (try_pipe2) {
+ ret = pipe2(fildes, O_CLOEXEC);
+ if (ret != -1)
+ return ret;
+ /* pipe2 is available since Linux 2.6.27. */
+ if (errno == ENOSYS) {
+ try_pipe2 = 0;
+ ret = pipe(fildes);
+ }
+ }
+ else {
+ ret = pipe(fildes);
+ }
+#else
ret = pipe(fildes);
+#endif
if (ret == -1) return -1;
#ifdef __CYGWIN__
if (ret == 0 && fildes[1] == -1) {