summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-29 02:33:28 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-29 02:33:28 +0000
commit3ae3cd741d4ac85e2cd53c588318afb582412fd9 (patch)
treea86ed498d553757bb0f59208a44d73c175a27d5e /io.c
parentd498620a7b70ea8adbc6d6ba0f1ab29943638b72 (diff)
* include/ruby/intern.h (rb_cloexec_open): declared.
* io.c (fd_set_cloexec): extracted from rb_fd_set_cloexec. (rb_cloexec_open): new function. (sysopen_func): use rb_cloexec_open. (rb_sysopen_internal): use rb_update_max_fd instead of rb_fd_set_cloexec. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/io.c b/io.c
index 35157ec6ff..806d095139 100644
--- a/io.c
+++ b/io.c
@@ -157,7 +157,8 @@ rb_update_max_fd(int fd)
if (max_file_descriptor < fd) max_file_descriptor = fd;
}
-void rb_fd_set_cloexec(int fd)
+static void
+fd_set_cloexec(int fd)
{
/* MinGW don't have F_GETFD and FD_CLOEXEC. [ruby-core:40281] */
#ifdef F_GETFD
@@ -176,9 +177,27 @@ void rb_fd_set_cloexec(int fd)
}
}
#endif
+}
+
+void
+rb_fd_set_cloexec(int fd)
+{
+ fd_set_cloexec(fd);
if (max_file_descriptor < fd) max_file_descriptor = fd;
}
+
+int
+rb_cloexec_open(const char *pathname, int flags, mode_t mode)
+{
+ int ret;
+ ret = open(pathname, flags, mode);
+ if (ret == -1) return -1;
+ fd_set_cloexec(ret);
+ return ret;
+}
+
+
#define argf_of(obj) (*(struct argf *)DATA_PTR(obj))
#define ARGF argf_of(argf)
@@ -4604,7 +4623,7 @@ sysopen_func(void *ptr)
{
const struct sysopen_struct *data = ptr;
const char *fname = RSTRING_PTR(data->fname);
- return (VALUE)open(fname, data->oflags, data->perm);
+ return (VALUE)rb_cloexec_open(fname, data->oflags, data->perm);
}
static inline int
@@ -4613,7 +4632,7 @@ rb_sysopen_internal(struct sysopen_struct *data)
int fd;
fd = (int)rb_thread_blocking_region(sysopen_func, data, RUBY_UBF_IO, 0);
if (0 <= fd)
- rb_fd_set_cloexec(fd);
+ rb_update_max_fd(fd);
return fd;
}