ruby-changes:20539
From: akr <ko1@a...>
Date: Wed, 20 Jul 2011 22:26:30 +0900 (JST)
Subject: [ruby-changes:20539] akr:r32587 (trunk): * include/ruby/intern.h (rb_update_max_fd): declaration moved from
akr 2011-07-20 22:26:10 +0900 (Wed, 20 Jul 2011) New Revision: 32587 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32587 Log: * 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. Modified files: trunk/ChangeLog trunk/ext/io/console/console.c trunk/ext/openssl/ossl_bio.c trunk/ext/pty/pty.c trunk/ext/socket/ancdata.c trunk/ext/socket/init.c trunk/ext/socket/socket.c trunk/ext/socket/unixsocket.c trunk/file.c trunk/include/ruby/intern.h trunk/internal.h trunk/io.c trunk/process.c trunk/random.c trunk/ruby.c Index: include/ruby/intern.h =================================================================== --- include/ruby/intern.h (revision 32586) +++ include/ruby/intern.h (revision 32587) @@ -499,6 +499,7 @@ 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); Index: ChangeLog =================================================================== --- ChangeLog (revision 32586) +++ ChangeLog (revision 32587) @@ -1,3 +1,32 @@ +Wed Jul 20 22:22:23 2011 Tanaka Akira <akr@f...> + + * 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@r...> * ext/dl/handle.c (dlhandle_sym): clear previous error with dlerror() Index: io.c =================================================================== --- io.c (revision 32586) +++ io.c (revision 32587) @@ -4592,7 +4592,11 @@ 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 @@ /* 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 @@ 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 @@ 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; } Index: process.c =================================================================== --- process.c (revision 32586) +++ process.c (revision 32587) @@ -1950,6 +1950,7 @@ 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 @@ 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 @@ ERRMSG("dup"); goto fail; } + rb_update_max_fd(extra_fd); } else { ret = redirect_dup2(pairs[i].oldfd, extra_fd); @@ -2111,6 +2114,7 @@ ERRMSG("dup2"); goto fail; } + rb_update_max_fd(extra_fd); } pairs[i].oldfd = extra_fd; j = pairs[i].older_index; @@ -2121,6 +2125,7 @@ ERRMSG("dup2"); goto fail; } + rb_update_max_fd(ret); pairs[j].oldfd = -1; j = pairs[j].older_index; } @@ -2178,6 +2183,7 @@ 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 @@ ERRMSG("dup2"); return -1; } + rb_update_max_fd(fd); } i++; } @@ -2224,6 +2231,7 @@ ERRMSG("dup2"); return -1; } + rb_update_max_fd(newfd); } return 0; } @@ -2490,6 +2498,7 @@ 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 @@ 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 @@ 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); Index: ext/pty/pty.c =================================================================== --- ext/pty/pty.c (revision 32586) +++ ext/pty/pty.c (revision 32587) @@ -177,6 +177,7 @@ { 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 @@ if (slave < 0) { ERROR_EXIT("open: pty slave"); } + rb_update_max_fd(slave); close(master); #endif dup2(slave,0); @@ -289,6 +291,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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); Index: ext/openssl/ossl_bio.c =================================================================== --- ext/openssl/ossl_bio.c (revision 32586) +++ ext/openssl/ossl_bio.c (revision 32587) @@ -28,6 +28,7 @@ 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); Index: ext/socket/init.c =================================================================== --- ext/socket/init.c (revision 32586) +++ ext/socket/init.c (revision 32587) @@ -48,6 +48,7 @@ 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 @@ fd = socket(domain, type, proto); } } + if (0 <= fd) + rb_update_max_fd(fd); return fd; } @@ -463,6 +466,7 @@ } 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 @@ } rb_sys_fail(0); } + rb_update_max_fd(fd2); if (!klass) return INT2NUM(fd2); return rsock_init_sock(rb_obj_alloc(klass), fd2); } Index: ext/socket/socket.c =================================================================== --- ext/socket/socket.c (revision 32586) +++ ext/socket/socket.c (revision 32587) @@ -119,6 +119,8 @@ 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]); Index: ext/socket/ancdata.c =================================================================== --- ext/socket/ancdata.c (revision 32586) +++ ext/socket/ancdata.c (revision 32587) @@ -1384,6 +1384,7 @@ 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 @@ 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 Index: ext/socket/unixsocket.c =================================================================== --- ext/socket/unixsocket.c (revision 32586) +++ ext/socket/unixsocket.c (revision 32587) @@ -383,6 +383,7 @@ #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); Index: ext/io/console/console.c =================================================================== --- ext/io/console/console.c (revision 32586) +++ ext/io/console/console.c (revision 32587) @@ -562,6 +562,7 @@ #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 @@ #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); Index: internal.h =================================================================== --- internal.h (revision 32586) +++ internal.h (revision 32587) @@ -101,7 +101,6 @@ 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); Index: ruby.c =================================================================== --- ruby.c (revision 32586) +++ ruby.c (revision 32587) @@ -1527,6 +1527,7 @@ if ((fd = open(fname, mode)) < 0) { rb_load_fail(fname); } + rb_update_max_fd(fd); f = rb_io_fdopen(fd, mode, fname); } Index: file.c =================================================================== --- file.c (revision 32586) +++ file.c (revision 32587) @@ -3914,6 +3914,7 @@ 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 @@ 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; Index: random.c =================================================================== --- random.c (revision 32586) +++ random.c (revision 32587) @@ -512,6 +512,7 @@ |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 */; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/