1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* io.c (rb_maygvl_fd_fix_cloexec): renamed from fd_set_cloexec.

* internal.h (rb_maygvl_fd_fix_cloexec): declared.

* ext/socket/init.c (cloexec_accept): use rb_maygvl_fd_fix_cloexec.
  (rsock_s_accept_nonblock): use rb_update_max_fd.
  (rsock_s_accept): use rb_update_max_fd.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2011-11-01 03:04:03 +00:00
parent 632f448827
commit c16f98ab0a
4 changed files with 32 additions and 14 deletions

View file

@ -1,3 +1,13 @@
Tue Nov 1 12:00:53 2011 Tanaka Akira <akr@fsij.org>
* io.c (rb_maygvl_fd_fix_cloexec): renamed from fd_set_cloexec.
* internal.h (rb_maygvl_fd_fix_cloexec): declared.
* ext/socket/init.c (cloexec_accept): use rb_maygvl_fd_fix_cloexec.
(rsock_s_accept_nonblock): use rb_update_max_fd.
(rsock_s_accept): use rb_update_max_fd.
Tue Nov 1 08:24:40 2011 Tanaka Akira <akr@fsij.org>
* ext/socket/init.c (cloexec_accept): new function to use accept4 if

View file

@ -472,7 +472,12 @@ cloexec_accept(int socket, struct sockaddr *address, socklen_t *address_len)
if (try_accept4) {
ret = accept4(socket, address, address_len, SOCK_CLOEXEC);
/* accept4 is available since Linux 2.6.28, glibc 2.10. */
if (ret == -1 && errno == ENOSYS) {
if (ret != -1) {
if (ret <= 2)
rb_maygvl_fd_fix_cloexec(ret);
return ret;
}
if (errno == ENOSYS) {
try_accept4 = 0;
ret = accept(socket, address, address_len);
}
@ -483,6 +488,8 @@ cloexec_accept(int socket, struct sockaddr *address, socklen_t *address_len)
#else
ret = accept(socket, address, address_len);
#endif
if (ret == -1) return -1;
rb_maygvl_fd_fix_cloexec(ret);
return ret;
}
@ -509,7 +516,7 @@ rsock_s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, s
}
rb_sys_fail("accept(2)");
}
rb_fd_fix_cloexec(fd2);
rb_update_max_fd(fd2);
make_fd_nonblock(fd2);
return rsock_init_sock(rb_obj_alloc(klass), fd2);
}
@ -556,7 +563,7 @@ rsock_s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
}
rb_sys_fail(0);
}
rb_fd_fix_cloexec(fd2);
rb_update_max_fd(fd2);
if (!klass) return INT2NUM(fd2);
return rsock_init_sock(rb_obj_alloc(klass), fd2);
}

View file

@ -102,6 +102,7 @@ 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_maygvl_fd_fix_cloexec(int fd);
/* iseq.c */
VALUE rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE filepath, VALUE line, VALUE opt);

22
io.c
View file

@ -157,15 +157,15 @@ rb_update_max_fd(int fd)
if (max_file_descriptor < fd) max_file_descriptor = fd;
}
static void
fd_set_cloexec(int fd)
void
rb_maygvl_fd_fix_cloexec(int fd)
{
/* MinGW don't have F_GETFD and FD_CLOEXEC. [ruby-core:40281] */
#ifdef F_GETFD
int flags, flags2, ret;
flags = fcntl(fd, F_GETFD); /* should not fail except EBADF. */
if (flags == -1) {
rb_bug("fd_set_cloexec: fcntl(%d, F_GETFD) failed: %s", fd, strerror(errno));
rb_bug("rb_maygvl_fd_fix_cloexec: fcntl(%d, F_GETFD) failed: %s", fd, strerror(errno));
}
if (fd <= 2)
flags2 = flags & ~FD_CLOEXEC; /* Clear CLOEXEC for standard file descriptors: 0, 1, 2. */
@ -174,7 +174,7 @@ fd_set_cloexec(int fd)
if (flags != flags2) {
ret = fcntl(fd, F_SETFD, flags2);
if (ret == -1) {
rb_bug("fd_set_cloexec: fcntl(%d, F_SETFD, %d) failed: %s", fd, flags2, strerror(errno));
rb_bug("rb_maygvl_fd_fix_cloexec: fcntl(%d, F_SETFD, %d) failed: %s", fd, flags2, strerror(errno));
}
}
#endif
@ -183,7 +183,7 @@ fd_set_cloexec(int fd)
void
rb_fd_fix_cloexec(int fd)
{
fd_set_cloexec(fd);
rb_maygvl_fd_fix_cloexec(fd);
if (max_file_descriptor < fd) max_file_descriptor = fd;
}
@ -198,7 +198,7 @@ rb_cloexec_open(const char *pathname, int flags, mode_t mode)
#endif
ret = open(pathname, flags, mode);
if (ret == -1) return -1;
fd_set_cloexec(ret);
rb_maygvl_fd_fix_cloexec(ret);
return ret;
}
@ -240,7 +240,7 @@ rb_cloexec_dup2(int oldfd, int newfd)
#endif
if (ret == -1) return -1;
}
fd_set_cloexec(ret);
rb_maygvl_fd_fix_cloexec(ret);
return ret;
}
@ -282,8 +282,8 @@ rb_cloexec_pipe(int fildes[2])
return -1;
}
#endif
fd_set_cloexec(fildes[0]);
fd_set_cloexec(fildes[1]);
rb_maygvl_fd_fix_cloexec(fildes[0]);
rb_maygvl_fd_fix_cloexec(fildes[1]);
return ret;
}
@ -298,7 +298,7 @@ rb_cloexec_fcntl_dupfd(int fd, int minfd)
ret = fcntl(fd, F_DUPFD_CLOEXEC, minfd);
if (ret != -1) {
if (ret <= 2)
fd_set_cloexec(ret);
rb_maygvl_fd_fix_cloexec(ret);
return ret;
}
/* F_DUPFD_CLOEXEC is available since Linux 2.6.24. Linux 2.6.18 fails with EINVAL */
@ -314,7 +314,7 @@ rb_cloexec_fcntl_dupfd(int fd, int minfd)
ret = fcntl(fd, F_DUPFD, minfd);
#endif
if (ret == -1) return -1;
fd_set_cloexec(ret);
rb_maygvl_fd_fix_cloexec(ret);
return ret;
}