ruby-changes:21571
From: akr <ko1@a...>
Date: Thu, 3 Nov 2011 22:46:51 +0900 (JST)
Subject: [ruby-changes:21571] akr:r33620 (trunk): * ext/socket/socket.c (rsock_socketpair0): extracted from
akr 2011-11-03 22:46:41 +0900 (Thu, 03 Nov 2011) New Revision: 33620 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33620 Log: * ext/socket/socket.c (rsock_socketpair0): extracted from rsock_socketpair to set close-on-exec flag for each socketpair() call. Modified files: trunk/ChangeLog trunk/ext/socket/socket.c Index: ChangeLog =================================================================== --- ChangeLog (revision 33619) +++ ChangeLog (revision 33620) @@ -1,3 +1,9 @@ +Thu Nov 3 22:45:09 2011 Tanaka Akira <akr@f...> + + * 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@g...> * ext/socket/init.c (rsock_socket): set close-on-exec flag when Index: ext/socket/socket.c =================================================================== --- ext/socket/socket.c (revision 33619) +++ ext/socket/socket.c (revision 33620) @@ -78,7 +78,7 @@ #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 @@ #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,15 +104,29 @@ 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; +} + /* * call-seq: * Socket.pair(domain, type, protocol) => [socket1, socket2] -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/