зеркало из https://github.com/github/ruby.git
* include/ruby/intern.h (rb_cloexec_dup): declared.
* io.c (rb_cloexec_dup): new function. (ruby_dup): use rb_cloexec_dup. * ext/pty/pty.c (pty_getpty): use rb_cloexec_dup. * ext/openssl/ossl_bio.c (ossl_obj2bio): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
3bffb5f306
Коммит
4ae2b92576
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
Sat Oct 29 20:00:26 2011 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* include/ruby/intern.h (rb_cloexec_dup): declared.
|
||||
|
||||
* io.c (rb_cloexec_dup): new function.
|
||||
(ruby_dup): use rb_cloexec_dup.
|
||||
|
||||
* ext/pty/pty.c (pty_getpty): use rb_cloexec_dup.
|
||||
|
||||
* ext/openssl/ossl_bio.c (ossl_obj2bio): ditto.
|
||||
|
||||
Sat Oct 29 16:11:34 2011 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* ext/sdbm/_sdbm.c (sdbm_prep): use O_CLOEXEC if available.
|
||||
|
|
|
@ -25,10 +25,10 @@ ossl_obj2bio(VALUE obj)
|
|||
|
||||
GetOpenFile(obj, fptr);
|
||||
rb_io_check_readable(fptr);
|
||||
if ((fd = dup(FPTR_TO_FD(fptr))) < 0){
|
||||
if ((fd = rb_cloexec_dup(FPTR_TO_FD(fptr))) < 0){
|
||||
rb_sys_fail(0);
|
||||
}
|
||||
rb_fd_set_cloexec(fd);
|
||||
rb_update_max_fd(fd);
|
||||
if (!(fp = fdopen(fd, "r"))){
|
||||
close(fd);
|
||||
rb_sys_fail(0);
|
||||
|
|
|
@ -603,10 +603,10 @@ pty_getpty(int argc, VALUE *argv, VALUE self)
|
|||
rfptr->pathv = rb_obj_freeze(rb_str_new_cstr(SlaveName));
|
||||
|
||||
wfptr->mode = rb_io_mode_flags("w") | FMODE_SYNC;
|
||||
wfptr->fd = dup(info.fd);
|
||||
wfptr->fd = rb_cloexec_dup(info.fd);
|
||||
if (wfptr->fd == -1)
|
||||
rb_sys_fail("dup()");
|
||||
rb_fd_set_cloexec(wfptr->fd);
|
||||
rb_update_max_fd(wfptr->fd);
|
||||
wfptr->pathv = rfptr->pathv;
|
||||
|
||||
res = rb_ary_new2(3);
|
||||
|
|
|
@ -503,6 +503,7 @@ 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);
|
||||
int rb_cloexec_dup(int oldfd);
|
||||
#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);
|
||||
|
|
15
io.c
15
io.c
|
@ -200,6 +200,15 @@ rb_cloexec_open(const char *pathname, int flags, mode_t mode)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
rb_cloexec_dup(int oldfd)
|
||||
{
|
||||
int ret;
|
||||
ret = dup(oldfd);
|
||||
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)
|
||||
|
@ -561,17 +570,17 @@ ruby_dup(int orig)
|
|||
{
|
||||
int fd;
|
||||
|
||||
fd = dup(orig);
|
||||
fd = rb_cloexec_dup(orig);
|
||||
if (fd < 0) {
|
||||
if (errno == EMFILE || errno == ENFILE || errno == ENOMEM) {
|
||||
rb_gc();
|
||||
fd = dup(orig);
|
||||
fd = rb_cloexec_dup(orig);
|
||||
}
|
||||
if (fd < 0) {
|
||||
rb_sys_fail(0);
|
||||
}
|
||||
}
|
||||
rb_fd_set_cloexec(fd);
|
||||
rb_update_max_fd(fd);
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче