зеркало из https://github.com/github/ruby.git
* include/ruby/intern.h (rb_update_max_fd): declaration moved from
internal.h. * file.c: ditto. * io.c: call rb_update_max_fd for each new fds. * process.c: ditto. * random.c: ditto. * ruby.c: ditto. * ext/io/console/console.c: ditto. * ext/openssl/ossl_bio.c: ditto. * ext/pty/pty.c: ditto. * ext/socket/init.c: ditto. * ext/socket/socket.c: ditto. * ext/socket/ancdata.c: ditto. * ext/socket/unixsocket.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32587 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
13f62a384b
Коммит
b41ccc4a9c
29
ChangeLog
29
ChangeLog
|
@ -1,3 +1,32 @@
|
|||
Wed Jul 20 22:22:23 2011 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* include/ruby/intern.h (rb_update_max_fd): declaration moved from
|
||||
internal.h.
|
||||
|
||||
* file.c: ditto.
|
||||
|
||||
* io.c: call rb_update_max_fd for each new fds.
|
||||
|
||||
* process.c: ditto.
|
||||
|
||||
* random.c: ditto.
|
||||
|
||||
* ruby.c: ditto.
|
||||
|
||||
* ext/io/console/console.c: ditto.
|
||||
|
||||
* ext/openssl/ossl_bio.c: ditto.
|
||||
|
||||
* ext/pty/pty.c: ditto.
|
||||
|
||||
* ext/socket/init.c: ditto.
|
||||
|
||||
* ext/socket/socket.c: ditto.
|
||||
|
||||
* ext/socket/ancdata.c: ditto.
|
||||
|
||||
* ext/socket/unixsocket.c: ditto.
|
||||
|
||||
Wed Jul 20 15:16:22 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* ext/dl/handle.c (dlhandle_sym): clear previous error with dlerror()
|
||||
|
|
|
@ -562,6 +562,7 @@ console_dev(VALUE klass)
|
|||
#ifdef CONSOLE_DEVICE_FOR_WRITING
|
||||
fd = open(CONSOLE_DEVICE_FOR_WRITING, O_WRONLY);
|
||||
if (fd < 0) return Qnil;
|
||||
rb_update_max_fd(fd);
|
||||
args[1] = INT2FIX(O_WRONLY);
|
||||
args[0] = INT2NUM(fd);
|
||||
out = rb_class_new_instance(2, args, klass);
|
||||
|
@ -573,6 +574,7 @@ console_dev(VALUE klass)
|
|||
#endif
|
||||
return Qnil;
|
||||
}
|
||||
rb_update_max_fd(fd);
|
||||
args[1] = INT2FIX(O_RDWR);
|
||||
args[0] = INT2NUM(fd);
|
||||
con = rb_class_new_instance(2, args, klass);
|
||||
|
|
|
@ -28,6 +28,7 @@ ossl_obj2bio(VALUE obj)
|
|||
if ((fd = dup(FPTR_TO_FD(fptr))) < 0){
|
||||
rb_sys_fail(0);
|
||||
}
|
||||
rb_update_max_fd(fd);
|
||||
if (!(fp = fdopen(fd, "r"))){
|
||||
close(fd);
|
||||
rb_sys_fail(0);
|
||||
|
|
|
@ -177,6 +177,7 @@ chfunc(void *data, char *errbuf, size_t errbuf_len)
|
|||
{
|
||||
int i = open("/dev/tty", O_RDONLY);
|
||||
if (i < 0) ERROR_EXIT("/dev/tty");
|
||||
rb_update_max_fd(i);
|
||||
if (ioctl(i, TIOCNOTTY, (char *)0))
|
||||
ERROR_EXIT("ioctl(TIOCNOTTY)");
|
||||
close(i);
|
||||
|
@ -198,6 +199,7 @@ chfunc(void *data, char *errbuf, size_t errbuf_len)
|
|||
if (slave < 0) {
|
||||
ERROR_EXIT("open: pty slave");
|
||||
}
|
||||
rb_update_max_fd(slave);
|
||||
close(master);
|
||||
#endif
|
||||
dup2(slave,0);
|
||||
|
@ -289,6 +291,7 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
|
|||
sigemptyset(&dfl.sa_mask);
|
||||
|
||||
if ((masterfd = posix_openpt(O_RDWR|O_NOCTTY)) == -1) goto error;
|
||||
rb_update_max_fd(masterfd);
|
||||
if (sigaction(SIGCHLD, &dfl, &old) == -1) goto error;
|
||||
if (grantpt(masterfd) == -1) goto grantpt_error;
|
||||
if (sigaction(SIGCHLD, &old, NULL) == -1) goto error;
|
||||
|
@ -296,6 +299,7 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
|
|||
if ((slavedevice = ptsname(masterfd)) == NULL) goto error;
|
||||
if (no_mesg(slavedevice, nomesg) == -1) goto error;
|
||||
if ((slavefd = open(slavedevice, O_RDWR|O_NOCTTY, 0)) == -1) goto error;
|
||||
rb_update_max_fd(slavefd);
|
||||
|
||||
#if defined I_PUSH && !defined linux
|
||||
if (ioctl(slavefd, I_PUSH, "ptem") == -1) goto error;
|
||||
|
@ -327,6 +331,8 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
|
|||
if (!fail) return -1;
|
||||
rb_raise(rb_eRuntimeError, "openpty() failed");
|
||||
}
|
||||
rb_update_max_fd(*master);
|
||||
rb_update_max_fd(*slave);
|
||||
if (no_mesg(SlaveName, nomesg) == -1) {
|
||||
if (!fail) return -1;
|
||||
rb_raise(rb_eRuntimeError, "can't chmod slave pty");
|
||||
|
@ -342,8 +348,11 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
|
|||
if (!fail) return -1;
|
||||
rb_raise(rb_eRuntimeError, "_getpty() failed");
|
||||
}
|
||||
rb_update_max_fd(*master);
|
||||
|
||||
*slave = open(name, O_RDWR);
|
||||
/* error check? */
|
||||
rb_update_max_fd(*slave);
|
||||
strlcpy(SlaveName, name, DEVICELEN);
|
||||
|
||||
return 0;
|
||||
|
@ -357,6 +366,7 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
|
|||
extern int grantpt(int);
|
||||
|
||||
if((masterfd = open("/dev/ptmx", O_RDWR, 0)) == -1) goto error;
|
||||
rb_update_max_fd(masterfd);
|
||||
s = signal(SIGCHLD, SIG_DFL);
|
||||
if(grantpt(masterfd) == -1) goto error;
|
||||
signal(SIGCHLD, s);
|
||||
|
@ -364,6 +374,7 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
|
|||
if((slavedevice = ptsname(masterfd)) == NULL) goto error;
|
||||
if (no_mesg(slavedevice, nomesg) == -1) goto error;
|
||||
if((slavefd = open(slavedevice, O_RDWR, 0)) == -1) goto error;
|
||||
rb_update_max_fd(slavefd);
|
||||
#if defined I_PUSH && !defined linux
|
||||
if(ioctl(slavefd, I_PUSH, "ptem") == -1) goto error;
|
||||
if(ioctl(slavefd, I_PUSH, "ldterm") == -1) goto error;
|
||||
|
@ -387,9 +398,11 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg,
|
|||
for (p = deviceNo; *p != NULL; p++) {
|
||||
snprintf(MasterName, sizeof MasterName, MasterDevice, *p);
|
||||
if ((masterfd = open(MasterName,O_RDWR,0)) >= 0) {
|
||||
rb_update_max_fd(masterfd);
|
||||
*master = masterfd;
|
||||
snprintf(SlaveName, DEVICELEN, SlaveDevice, *p);
|
||||
if ((slavefd = open(SlaveName,O_RDWR,0)) >= 0) {
|
||||
rb_update_max_fd(slavefd);
|
||||
*slave = slavefd;
|
||||
if (chown(SlaveName, getuid(), getgid()) != 0) goto error;
|
||||
if (chmod(SlaveName, nomesg ? 0600 : 0622) != 0) goto error;
|
||||
|
@ -577,6 +590,7 @@ pty_getpty(int argc, VALUE *argv, VALUE self)
|
|||
wfptr->fd = dup(info.fd);
|
||||
if (wfptr->fd == -1)
|
||||
rb_sys_fail("dup()");
|
||||
rb_update_max_fd(wfptr->fd);
|
||||
wfptr->pathv = rfptr->pathv;
|
||||
|
||||
res = rb_ary_new2(3);
|
||||
|
|
|
@ -1384,6 +1384,7 @@ discard_cmsg(struct cmsghdr *cmh, char *msg_end)
|
|||
int *end = (int *)((char *)cmh + cmh->cmsg_len);
|
||||
while ((char *)fdp + sizeof(int) <= (char *)end &&
|
||||
(char *)fdp + sizeof(int) <= msg_end) {
|
||||
rb_update_max_fd(*fdp);
|
||||
close(*fdp);
|
||||
fdp++;
|
||||
}
|
||||
|
@ -1426,6 +1427,7 @@ make_io_for_unix_rights(VALUE ctl, struct cmsghdr *cmh, char *msg_end)
|
|||
VALUE io;
|
||||
if (fstat(fd, &stbuf) == -1)
|
||||
rb_raise(rb_eSocket, "invalid fd in SCM_RIGHTS");
|
||||
rb_update_max_fd(fd);
|
||||
if (S_ISSOCK(stbuf.st_mode))
|
||||
io = rsock_init_sock(rb_obj_alloc(rb_cSocket), fd);
|
||||
else
|
||||
|
|
|
@ -48,6 +48,7 @@ rsock_init_sock(VALUE sock, int fd)
|
|||
|
||||
if (fstat(fd, &sbuf) < 0)
|
||||
rb_sys_fail(0);
|
||||
rb_update_max_fd(fd);
|
||||
if (!S_ISSOCK(sbuf.st_mode))
|
||||
rb_raise(rb_eArgError, "not a socket file descriptor");
|
||||
#else
|
||||
|
@ -250,6 +251,8 @@ rsock_socket(int domain, int type, int proto)
|
|||
fd = socket(domain, type, proto);
|
||||
}
|
||||
}
|
||||
if (0 <= fd)
|
||||
rb_update_max_fd(fd);
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
@ -463,6 +466,7 @@ rsock_s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, s
|
|||
}
|
||||
rb_sys_fail("accept(2)");
|
||||
}
|
||||
rb_update_max_fd(fd2);
|
||||
make_fd_nonblock(fd2);
|
||||
return rsock_init_sock(rb_obj_alloc(klass), fd2);
|
||||
}
|
||||
|
@ -509,6 +513,7 @@ rsock_s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
|
|||
}
|
||||
rb_sys_fail(0);
|
||||
}
|
||||
rb_update_max_fd(fd2);
|
||||
if (!klass) return INT2NUM(fd2);
|
||||
return rsock_init_sock(rb_obj_alloc(klass), fd2);
|
||||
}
|
||||
|
|
|
@ -119,6 +119,8 @@ rsock_sock_s_socketpair(int argc, VALUE *argv, VALUE klass)
|
|||
if (ret < 0) {
|
||||
rb_sys_fail("socketpair(2)");
|
||||
}
|
||||
rb_update_max_fd(sp[0]);
|
||||
rb_update_max_fd(sp[1]);
|
||||
|
||||
s1 = rsock_init_sock(rb_obj_alloc(klass), sp[0]);
|
||||
s2 = rsock_init_sock(rb_obj_alloc(klass), sp[1]);
|
||||
|
|
|
@ -383,6 +383,7 @@ unix_recv_io(int argc, VALUE *argv, VALUE sock)
|
|||
#if FD_PASSING_BY_MSG_CONTROL
|
||||
memcpy(&fd, CMSG_DATA(&cmsg.hdr), sizeof(int));
|
||||
#endif
|
||||
rb_update_max_fd(fd);
|
||||
|
||||
if (klass == Qnil)
|
||||
return INT2FIX(fd);
|
||||
|
|
2
file.c
2
file.c
|
@ -3914,6 +3914,7 @@ rb_file_s_truncate(VALUE klass, VALUE path, VALUE len)
|
|||
if ((tmpfd = open(StringValueCStr(path), 0)) < 0) {
|
||||
rb_sys_fail(RSTRING_PTR(path));
|
||||
}
|
||||
rb_update_max_fd(tmpfd);
|
||||
if (chsize(tmpfd, pos) < 0) {
|
||||
close(tmpfd);
|
||||
rb_sys_fail(RSTRING_PTR(path));
|
||||
|
@ -5061,6 +5062,7 @@ file_load_ok(const char *path)
|
|||
int ret = 1;
|
||||
int fd = open(path, O_RDONLY);
|
||||
if (fd == -1) return 0;
|
||||
rb_update_max_fd(fd);
|
||||
#if !defined DOSISH
|
||||
{
|
||||
struct stat st;
|
||||
|
|
|
@ -499,6 +499,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);
|
||||
#define RB_RESERVED_FD_P(fd) rb_reserved_fd_p(fd)
|
||||
void rb_update_max_fd(int fd);
|
||||
/* marshal.c */
|
||||
VALUE rb_marshal_dump(VALUE, VALUE);
|
||||
VALUE rb_marshal_load(VALUE);
|
||||
|
|
|
@ -101,7 +101,6 @@ const char *ruby_get_inplace_mode(void);
|
|||
void ruby_set_inplace_mode(const char *);
|
||||
ssize_t rb_io_bufread(VALUE io, void *buf, size_t size);
|
||||
void rb_stdio_set_default_encoding(void);
|
||||
void rb_update_max_fd(int fd);
|
||||
|
||||
/* iseq.c */
|
||||
VALUE rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE filepath, VALUE line, VALUE opt);
|
||||
|
|
9
io.c
9
io.c
|
@ -4592,7 +4592,11 @@ sysopen_func(void *ptr)
|
|||
static inline int
|
||||
rb_sysopen_internal(struct sysopen_struct *data)
|
||||
{
|
||||
return (int)rb_thread_blocking_region(sysopen_func, data, RUBY_UBF_IO, 0);
|
||||
int fd;
|
||||
fd = (int)rb_thread_blocking_region(sysopen_func, data, RUBY_UBF_IO, 0);
|
||||
if (0 <= fd)
|
||||
rb_update_max_fd(fd);
|
||||
return fd;
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -5794,6 +5798,7 @@ io_reopen(VALUE io, VALUE nfile)
|
|||
/* need to keep FILE objects of stdin, stdout and stderr */
|
||||
if (dup2(fd2, fd) < 0)
|
||||
rb_sys_fail_path(orig->pathv);
|
||||
rb_update_max_fd(fd);
|
||||
}
|
||||
else {
|
||||
fclose(fptr->stdio_file);
|
||||
|
@ -5801,6 +5806,7 @@ io_reopen(VALUE io, VALUE nfile)
|
|||
fptr->fd = -1;
|
||||
if (dup2(fd2, fd) < 0)
|
||||
rb_sys_fail_path(orig->pathv);
|
||||
rb_update_max_fd(fd);
|
||||
fptr->fd = fd;
|
||||
}
|
||||
rb_thread_fd_close(fd);
|
||||
|
@ -6384,6 +6390,7 @@ prep_io(int fd, int fmode, VALUE klass, const char *path)
|
|||
fp->mode = fmode;
|
||||
io_check_tty(fp);
|
||||
if (path) fp->pathv = rb_obj_freeze(rb_str_new_cstr(path));
|
||||
rb_update_max_fd(fd);
|
||||
|
||||
return io;
|
||||
}
|
||||
|
|
11
process.c
11
process.c
|
@ -1950,6 +1950,7 @@ save_redirect_fd(int fd, VALUE save, char *errmsg, size_t errmsg_buflen)
|
|||
ERRMSG("dup");
|
||||
return -1;
|
||||
}
|
||||
rb_update_max_fd(save_fd);
|
||||
newary = rb_ary_entry(save, EXEC_OPTION_DUP2);
|
||||
if (NIL_P(newary)) {
|
||||
newary = hide_obj(rb_ary_new());
|
||||
|
@ -2066,6 +2067,7 @@ run_exec_dup2(VALUE ary, VALUE save, char *errmsg, size_t errmsg_buflen)
|
|||
ERRMSG("dup2");
|
||||
goto fail;
|
||||
}
|
||||
rb_update_max_fd(pairs[j].newfd);
|
||||
pairs[j].oldfd = -1;
|
||||
j = pairs[j].older_index;
|
||||
if (j != -1)
|
||||
|
@ -2104,6 +2106,7 @@ run_exec_dup2(VALUE ary, VALUE save, char *errmsg, size_t errmsg_buflen)
|
|||
ERRMSG("dup");
|
||||
goto fail;
|
||||
}
|
||||
rb_update_max_fd(extra_fd);
|
||||
}
|
||||
else {
|
||||
ret = redirect_dup2(pairs[i].oldfd, extra_fd);
|
||||
|
@ -2111,6 +2114,7 @@ run_exec_dup2(VALUE ary, VALUE save, char *errmsg, size_t errmsg_buflen)
|
|||
ERRMSG("dup2");
|
||||
goto fail;
|
||||
}
|
||||
rb_update_max_fd(extra_fd);
|
||||
}
|
||||
pairs[i].oldfd = extra_fd;
|
||||
j = pairs[i].older_index;
|
||||
|
@ -2121,6 +2125,7 @@ run_exec_dup2(VALUE ary, VALUE save, char *errmsg, size_t errmsg_buflen)
|
|||
ERRMSG("dup2");
|
||||
goto fail;
|
||||
}
|
||||
rb_update_max_fd(ret);
|
||||
pairs[j].oldfd = -1;
|
||||
j = pairs[j].older_index;
|
||||
}
|
||||
|
@ -2178,6 +2183,7 @@ run_exec_open(VALUE ary, VALUE save, char *errmsg, size_t errmsg_buflen)
|
|||
ERRMSG("open");
|
||||
return -1;
|
||||
}
|
||||
rb_update_max_fd(fd2);
|
||||
while (i < RARRAY_LEN(ary) &&
|
||||
(elt = RARRAY_PTR(ary)[i], RARRAY_PTR(elt)[1] == param)) {
|
||||
fd = FIX2INT(RARRAY_PTR(elt)[0]);
|
||||
|
@ -2192,6 +2198,7 @@ run_exec_open(VALUE ary, VALUE save, char *errmsg, size_t errmsg_buflen)
|
|||
ERRMSG("dup2");
|
||||
return -1;
|
||||
}
|
||||
rb_update_max_fd(fd);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
@ -2224,6 +2231,7 @@ run_exec_dup2_child(VALUE ary, VALUE save, char *errmsg, size_t errmsg_buflen)
|
|||
ERRMSG("dup2");
|
||||
return -1;
|
||||
}
|
||||
rb_update_max_fd(newfd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -2490,6 +2498,7 @@ move_fds_to_avoid_crash(int *fdp, int n, VALUE fds)
|
|||
ret = fcntl(fdp[i], F_DUPFD, min);
|
||||
if (ret == -1)
|
||||
return -1;
|
||||
rb_update_max_fd(ret);
|
||||
close(fdp[i]);
|
||||
fdp[i] = ret;
|
||||
}
|
||||
|
@ -3538,6 +3547,7 @@ ruby_setsid(void)
|
|||
if (ret == -1) return -1;
|
||||
|
||||
if ((fd = open("/dev/tty", O_RDWR)) >= 0) {
|
||||
rb_update_max_fd(fd);
|
||||
ioctl(fd, TIOCNOTTY, NULL);
|
||||
close(fd);
|
||||
}
|
||||
|
@ -4828,6 +4838,7 @@ rb_daemon(int nochdir, int noclose)
|
|||
err = chdir("/");
|
||||
|
||||
if (!noclose && (n = open("/dev/null", O_RDWR, 0)) != -1) {
|
||||
rb_update_max_fd(n);
|
||||
(void)dup2(n, 0);
|
||||
(void)dup2(n, 1);
|
||||
(void)dup2(n, 2);
|
||||
|
|
1
random.c
1
random.c
|
@ -512,6 +512,7 @@ fill_random_seed(unsigned int seed[DEFAULT_SEED_CNT])
|
|||
|O_NOCTTY
|
||||
#endif
|
||||
)) >= 0) {
|
||||
rb_update_max_fd(fd);
|
||||
if (fstat(fd, &statbuf) == 0 && S_ISCHR(statbuf.st_mode)) {
|
||||
if (read(fd, seed, DEFAULT_SEED_LEN) < DEFAULT_SEED_LEN) {
|
||||
/* abandon */;
|
||||
|
|
1
ruby.c
1
ruby.c
|
@ -1527,6 +1527,7 @@ load_file_internal(VALUE arg)
|
|||
if ((fd = open(fname, mode)) < 0) {
|
||||
rb_load_fail(fname);
|
||||
}
|
||||
rb_update_max_fd(fd);
|
||||
|
||||
f = rb_io_fdopen(fd, mode, fname);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче