summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--ext/socket/init.c13
-rw-r--r--internal.h1
-rw-r--r--io.c22
4 files changed, 32 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 258edf3ce6..f1a7c28d95 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/ext/socket/init.c b/ext/socket/init.c
index a41f94a38f..ad25ccb080 100644
--- a/ext/socket/init.c
+++ b/ext/socket/init.c
@@ -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);
}
diff --git a/internal.h b/internal.h
index c7c921fe05..16eca49d03 100644
--- a/internal.h
+++ b/internal.h
@@ -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);
diff --git a/io.c b/io.c
index 80e6c28ce1..7ea40b320a 100644
--- a/io.c
+++ b/io.c
@@ -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;
}