summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-03 13:46:41 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-03 13:46:41 +0000
commitb45c882aec9d5d97261b11704c931c03f8d69639 (patch)
tree88edf0f773f0690a7231bf5b103da71b75b3f309
parenta0b22b1a39ec127d12689de200faf4addc2b5300 (diff)
* ext/socket/socket.c (rsock_socketpair0): extracted from
rsock_socketpair to set close-on-exec flag for each socketpair() call. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--ext/socket/socket.c27
2 files changed, 27 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index a748fd6b6c..98a8b2dc54 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Thu Nov 3 22:45:09 2011 Tanaka Akira <akr@fsij.org>
+
+ * ext/socket/socket.c (rsock_socketpair0): extracted from
+ rsock_socketpair to set close-on-exec flag for each socketpair()
+ call.
+
Thu Nov 3 22:12:41 2011 CHIKANAGA Tomoyuki <nagachika00@gmail.com>
* ext/socket/init.c (rsock_socket): set close-on-exec flag when
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index aa1749bb4a..0752793d88 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -78,7 +78,7 @@ pair_yield(VALUE pair)
#if defined HAVE_SOCKETPAIR
static int
-rsock_socketpair(int domain, int type0, int protocol, int sv[2])
+rsock_socketpair0(int domain, int type0, int protocol, int sv[2])
{
int ret, type;
@@ -94,7 +94,8 @@ rsock_socketpair(int domain, int type0, int protocol, int sv[2])
#endif
ret = socketpair(domain, type, protocol, sv);
- if (ret < 0) {
+
+ if (ret == -1) {
#ifdef SOCK_CLOEXEC
/* SOCK_CLOEXEC is available since Linux 2.6.27. Linux 2.6.18 fails with EINVAL */
if (try_sock_cloexec && errno == EINVAL) {
@@ -103,10 +104,24 @@ rsock_socketpair(int domain, int type0, int protocol, int sv[2])
goto retry_without_sock_cloexec;
}
#endif
- if (errno == EMFILE || errno == ENFILE) {
- rb_gc();
- ret = socketpair(domain, type, protocol, sv);
- }
+ return -1;
+ }
+
+ rb_fd_fix_cloexec(sv[0]);
+ rb_fd_fix_cloexec(sv[1]);
+
+ return ret;
+}
+
+static int
+rsock_socketpair(int domain, int type, int protocol, int sv[2])
+{
+ int ret;
+
+ ret = rsock_socketpair0(domain, type, protocol, sv);
+ if (ret < 0 && (errno == EMFILE || errno == ENFILE)) {
+ rb_gc();
+ ret = rsock_socketpair0(domain, type, protocol, sv);
}
return ret;