ruby-changes:21586
From: akr <ko1@a...>
Date: Sat, 5 Nov 2011 11:20:00 +0900 (JST)
Subject: [ruby-changes:21586] akr:r33635 (trunk): * ext/socket/socket.c (rsock_socketpair0): don't clear
akr 2011-11-05 11:19:48 +0900 (Sat, 05 Nov 2011) New Revision: 33635 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33635 Log: * ext/socket/socket.c (rsock_socketpair0): don't clear try_sock_cloexec if SOCK_CLOEXEC is not a reason for EINVAL. Modified files: trunk/ChangeLog trunk/ext/socket/socket.c Index: ChangeLog =================================================================== --- ChangeLog (revision 33634) +++ ChangeLog (revision 33635) @@ -1,3 +1,8 @@ +Sat Nov 5 11:18:12 2011 Tanaka Akira <akr@f...> + + * ext/socket/socket.c (rsock_socketpair0): don't clear + try_sock_cloexec if SOCK_CLOEXEC is not a reason for EINVAL. + Fri Nov 4 14:08:19 2011 Hiroshi Nakamura <nahi@r...> * ext/openssl/ossl_pkey_rsa.c (rsa_generate): [SECURITY] Set RSA Index: ext/socket/socket.c =================================================================== --- ext/socket/socket.c (revision 33634) +++ ext/socket/socket.c (revision 33635) @@ -78,32 +78,36 @@ #if defined HAVE_SOCKETPAIR static int -rsock_socketpair0(int domain, int type0, int protocol, int sv[2]) +rsock_socketpair0(int domain, int type, int protocol, int sv[2]) { - int ret, type; + int ret; #ifdef SOCK_CLOEXEC static int try_sock_cloexec = 1; - if (try_sock_cloexec) - type = type0|SOCK_CLOEXEC; - else - type = type0; - retry_without_sock_cloexec:; + if (try_sock_cloexec) { + ret = socketpair(domain, type|SOCK_CLOEXEC, protocol, sv); + if (ret == -1) { + /* SOCK_CLOEXEC is available since Linux 2.6.27. Linux 2.6.18 fails with EINVAL */ + if (try_sock_cloexec && errno == EINVAL) { + ret = socketpair(domain, type, protocol, sv); + if (ret != -1) { + /* The reason of EINVAL may be other than SOCK_CLOEXEC. + * So disable SOCK_CLOEXEC only if socketpair() succeeds without SOCK_CLOEXEC. + * Ex. Socket.pair(:UNIX, 0xff) fails with EINVAL. + */ + try_sock_cloexec = 0; + } + } + } + } + else { + ret = socketpair(domain, type, protocol, sv); + } #else - type = type0; + ret = socketpair(domain, type, protocol, sv); #endif - ret = socketpair(domain, type, protocol, sv); - 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) { - try_sock_cloexec = 0; - type = type0; - goto retry_without_sock_cloexec; - } -#endif return -1; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/