summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-30 01:02:46 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-30 01:02:46 +0000
commitf0b021c0cef7adbbca2574ceba4be6abacbdaf90 (patch)
tree0d706fe1d5f46d0597e0b297b308c804d66275b9 /io.c
parente745a03cfa60074b6d9569491f5932a74ee20e1b (diff)
* io.c (rb_cloexec_dup): don't allocate standard file descriptors.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/io.c b/io.c
index 1e04a1d6f5..d61dc5f31d 100644
--- a/io.c
+++ b/io.c
@@ -167,6 +167,7 @@ fd_set_cloexec(int fd)
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 @@ rb_cloexec_dup(int oldfd)
{
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 @@ rb_cloexec_dup(int oldfd)
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