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_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:
akr 2011-10-29 11:02:32 +00:00
parent 3bffb5f306
commit 4ae2b92576
5 changed files with 28 additions and 7 deletions

View file

@ -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.

View file

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

View file

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

View file

@ -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
View file

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