mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* include/ruby/intern.h (rb_cloexec_fcntl_dupfd): declared.
* io.c (rb_cloexec_fcntl_dupfd): new function. (nogvl_io_cntl): use rb_cloexec_fcntl_dupfd. * process.c (move_fds_to_avoid_crash): use rb_cloexec_fcntl_dupfd. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e7f8c03818
commit
5c19f07700
4 changed files with 27 additions and 4 deletions
|
@ -1,3 +1,12 @@
|
|||
Mon Oct 31 00:16:11 2011 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* include/ruby/intern.h (rb_cloexec_fcntl_dupfd): declared.
|
||||
|
||||
* io.c (rb_cloexec_fcntl_dupfd): new function.
|
||||
(nogvl_io_cntl): use rb_cloexec_fcntl_dupfd.
|
||||
|
||||
* process.c (move_fds_to_avoid_crash): use rb_cloexec_fcntl_dupfd.
|
||||
|
||||
Sun Oct 30 22:46:46 2011 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* configure.in: check pipe2.
|
||||
|
|
|
@ -506,6 +506,7 @@ int rb_cloexec_open(const char *pathname, int flags, mode_t mode);
|
|||
int rb_cloexec_dup(int oldfd);
|
||||
int rb_cloexec_dup2(int oldfd, int newfd);
|
||||
int rb_cloexec_pipe(int fildes[2]);
|
||||
int rb_cloexec_fcntl_dupfd(int fd, int minfd);
|
||||
#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);
|
||||
|
|
17
io.c
17
io.c
|
@ -299,6 +299,16 @@ rb_cloexec_pipe(int fildes[2])
|
|||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
rb_cloexec_fcntl_dupfd(int fd, int minfd)
|
||||
{
|
||||
int ret;
|
||||
ret = fcntl(fd, F_DUPFD, minfd);
|
||||
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)
|
||||
|
||||
|
@ -7821,7 +7831,10 @@ static VALUE nogvl_io_cntl(void *ptr)
|
|||
if (arg->io_p)
|
||||
return (VALUE)ioctl(arg->fd, arg->cmd, arg->narg);
|
||||
else
|
||||
return (VALUE)fcntl(arg->fd, arg->cmd, arg->narg);
|
||||
if (arg->cmd == F_DUPFD)
|
||||
return (VALUE)rb_cloexec_fcntl_dupfd(arg->fd, arg->narg);
|
||||
else
|
||||
return (VALUE)fcntl(arg->fd, arg->cmd, arg->narg);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -7844,7 +7857,7 @@ io_cntl(int fd, int cmd, long narg, int io_p)
|
|||
retval = (int)rb_thread_io_blocking_region(nogvl_io_cntl, &arg, fd);
|
||||
#if defined(F_DUPFD)
|
||||
if (!io_p && retval != -1 && cmd == F_DUPFD) {
|
||||
rb_fd_set_cloexec(retval);
|
||||
rb_update_max_fd(retval);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -2508,10 +2508,10 @@ move_fds_to_avoid_crash(int *fdp, int n, VALUE fds)
|
|||
min = fdp[i]+1;
|
||||
while (RTEST(rb_hash_lookup(fds, INT2FIX(min))))
|
||||
min++;
|
||||
ret = fcntl(fdp[i], F_DUPFD, min);
|
||||
ret = rb_cloexec_fcntl_dupfd(fdp[i], min);
|
||||
if (ret == -1)
|
||||
return -1;
|
||||
rb_fd_set_cloexec(ret);
|
||||
rb_update_max_fd(ret);
|
||||
close(fdp[i]);
|
||||
fdp[i] = ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue