Skip to content

Commit 4ae2b92

Browse files
committed
* 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
1 parent 3bffb5f commit 4ae2b92

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

ChangeLog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
Sat Oct 29 20:00:26 2011 Tanaka Akira <[email protected]>
2+
3+
* include/ruby/intern.h (rb_cloexec_dup): declared.
4+
5+
* io.c (rb_cloexec_dup): new function.
6+
(ruby_dup): use rb_cloexec_dup.
7+
8+
* ext/pty/pty.c (pty_getpty): use rb_cloexec_dup.
9+
10+
* ext/openssl/ossl_bio.c (ossl_obj2bio): ditto.
11+
112
Sat Oct 29 16:11:34 2011 Tanaka Akira <[email protected]>
213

314
* ext/sdbm/_sdbm.c (sdbm_prep): use O_CLOEXEC if available.

ext/openssl/ossl_bio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ ossl_obj2bio(VALUE obj)
2525

2626
GetOpenFile(obj, fptr);
2727
rb_io_check_readable(fptr);
28-
if ((fd = dup(FPTR_TO_FD(fptr))) < 0){
28+
if ((fd = rb_cloexec_dup(FPTR_TO_FD(fptr))) < 0){
2929
rb_sys_fail(0);
3030
}
31-
rb_fd_set_cloexec(fd);
31+
rb_update_max_fd(fd);
3232
if (!(fp = fdopen(fd, "r"))){
3333
close(fd);
3434
rb_sys_fail(0);

ext/pty/pty.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,10 +603,10 @@ pty_getpty(int argc, VALUE *argv, VALUE self)
603603
rfptr->pathv = rb_obj_freeze(rb_str_new_cstr(SlaveName));
604604

605605
wfptr->mode = rb_io_mode_flags("w") | FMODE_SYNC;
606-
wfptr->fd = dup(info.fd);
606+
wfptr->fd = rb_cloexec_dup(info.fd);
607607
if (wfptr->fd == -1)
608608
rb_sys_fail("dup()");
609-
rb_fd_set_cloexec(wfptr->fd);
609+
rb_update_max_fd(wfptr->fd);
610610
wfptr->pathv = rfptr->pathv;
611611

612612
res = rb_ary_new2(3);

include/ruby/intern.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ void rb_close_before_exec(int lowfd, int maxhint, VALUE noclose_fds);
503503
int rb_pipe(int *pipes);
504504
int rb_reserved_fd_p(int fd);
505505
int rb_cloexec_open(const char *pathname, int flags, mode_t mode);
506+
int rb_cloexec_dup(int oldfd);
506507
#define RB_RESERVED_FD_P(fd) rb_reserved_fd_p(fd)
507508
void rb_update_max_fd(int fd);
508509
void rb_fd_set_cloexec(int fd);

io.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ rb_cloexec_open(const char *pathname, int flags, mode_t mode)
200200
return ret;
201201
}
202202

203+
int
204+
rb_cloexec_dup(int oldfd)
205+
{
206+
int ret;
207+
ret = dup(oldfd);
208+
if (ret == -1) return -1;
209+
fd_set_cloexec(ret);
210+
return ret;
211+
}
203212

204213
#define argf_of(obj) (*(struct argf *)DATA_PTR(obj))
205214
#define ARGF argf_of(argf)
@@ -561,17 +570,17 @@ ruby_dup(int orig)
561570
{
562571
int fd;
563572

564-
fd = dup(orig);
573+
fd = rb_cloexec_dup(orig);
565574
if (fd < 0) {
566575
if (errno == EMFILE || errno == ENFILE || errno == ENOMEM) {
567576
rb_gc();
568-
fd = dup(orig);
577+
fd = rb_cloexec_dup(orig);
569578
}
570579
if (fd < 0) {
571580
rb_sys_fail(0);
572581
}
573582
}
574-
rb_fd_set_cloexec(fd);
583+
rb_update_max_fd(fd);
575584
return fd;
576585
}
577586

0 commit comments

Comments
 (0)