ruby-changes:10850
From: akr <ko1@a...>
Date: Wed, 18 Feb 2009 22:48:05 +0900 (JST)
Subject: [ruby-changes:10850] Ruby:r22420 (trunk): * ext/socket/ancdata.c (discard_cmsg_resource): new function to close
akr 2009-02-18 22:47:53 +0900 (Wed, 18 Feb 2009) New Revision: 22420 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=22420 Log: * ext/socket/ancdata.c (discard_cmsg_resource): new function to close file descriptors in control message. (bsock_recvmsg_internal): call discard_cmsg_resource before retrying recvmsg. Modified files: trunk/ChangeLog trunk/ext/socket/ancdata.c Index: ChangeLog =================================================================== --- ChangeLog (revision 22419) +++ ChangeLog (revision 22420) @@ -1,3 +1,10 @@ +Wed Feb 18 22:47:01 2009 Tanaka Akira <akr@f...> + + * ext/socket/ancdata.c (discard_cmsg_resource): new function to close + file descriptors in control message. + (bsock_recvmsg_internal): call discard_cmsg_resource before retrying + recvmsg. + Wed Feb 18 21:47:37 2009 Tanaka Akira <akr@f...> * ext/socket/ancdata.c (bsock_recvmsg_internal): prevent misalignment. Index: ext/socket/ancdata.c =================================================================== --- ext/socket/ancdata.c (revision 22419) +++ ext/socket/ancdata.c (revision 22420) @@ -1099,6 +1099,28 @@ return rb_thread_blocking_region(nogvl_recvmsg_func, &args, RUBY_UBF_IO, 0); } +static void +discard_cmsg_resource(struct msghdr *mh) +{ +#if defined(HAVE_ST_MSG_CONTROL) + struct cmsghdr *cmh; + + if (mh->msg_controllen == 0) + return; + + for (cmh = CMSG_FIRSTHDR(mh); cmh != NULL; cmh = CMSG_NXTHDR(mh, cmh)) { + if (cmh->cmsg_level == SOL_SOCKET && cmh->cmsg_type == SCM_RIGHTS) { + int *fdp = (int *)CMSG_DATA(cmh); + int *end = (int *)((char *)cmh + cmh->cmsg_len); + while (fdp < end) { + close(*fdp); + fdp++; + } + } + } +#endif +} + static VALUE bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock) { @@ -1232,12 +1254,14 @@ } #endif if (grown) { + discard_cmsg_resource(&mh); goto retry; } else { grow_buffer = 0; if (flags != orig_flags) { flags = orig_flags; + discard_cmsg_resource(&mh); goto retry; } } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/