1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
akr 2011-10-29 02:33:28 +00:00
parent d498620a7b
commit 3ae3cd741d
3 changed files with 33 additions and 3 deletions

View file

@ -1,3 +1,13 @@
Sat Oct 29 10:40:19 2011 Tanaka Akira <akr@fsij.org>
* 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.
Sat Oct 29 09:05:07 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* thread_pthread.h: no Structured Exception Handling like macros.

View file

@ -502,6 +502,7 @@ void rb_write_error2(const char*, long);
void rb_close_before_exec(int lowfd, int maxhint, VALUE noclose_fds);
int rb_pipe(int *pipes);
int rb_reserved_fd_p(int fd);
int rb_cloexec_open(const char *pathname, int flags, mode_t mode);
#define RB_RESERVED_FD_P(fd) rb_reserved_fd_p(fd)
void rb_update_max_fd(int fd);
void rb_fd_set_cloexec(int fd);

25
io.c
View file

@ -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;
}