[firstname.lastname@example.org: Re: ENOTSOCK errors with cygwin dll 1.3.21 and 1.3.22]
Mon May 26 16:47:00 GMT 2003
On Mon, May 26, 2003 at 05:31:20PM +0200, Corinna Vinschen wrote:
> On Mon, May 26, 2003 at 11:12:58AM -0400, Pierre A. Humblet wrote:
> > At 04:32 PM 5/26/2003 +0200, Corinna Vinschen wrote:
> > >That means, owner: Everyone, group: Everyone, No ACL.
> > There is also the issue that the bug comes up when the process is started
> > from Cygwin, not from Windows. How did you start your test case?
> Started from Cygwin of course. I'm reproducing the situation in which
> the dup fails, FWIW. The above SD would typically not invalidate the
> handle for a later dup'ing by a non-priv'd account. The more weird is
> the situation. I've already tried a couple of changes without any
> positive effect (Using inheritable sockets, duplicating the socket
> on creation with GENERIC_ALL access)...
Question: Would a working workaround be sufficient as long as we don't
quite understand why it fails?
What I did is, first fhandler_socket::dup now tries to duplicate the
socket by calling WSADuplicateSocket/WSASocket. If that fails, duplicate
the socket using DuplicateHandle.
It's ugly but it seems to work:
RCS file: /cvs/src/src/winsup/cygwin/fhandler_socket.cc,v
retrieving revision 1.95
diff -u -p -r1.95 fhandler_socket.cc
--- fhandler_socket.cc 26 May 2003 11:11:22 -0000 1.95
+++ fhandler_socket.cc 26 May 2003 16:43:35 -0000
@@ -393,15 +393,16 @@ fhandler_socket::dup (fhandler_base *chi
drop this for NT systems at all and return to the good ol'
DuplicateHandle way of life. This worked fine all the time on
NT anyway and it's even a bit faster. */
- if (!wincap.has_security ())
+ WSASetLastError (0);
+ fhs->fixup_before_fork_exec (GetCurrentProcessId ());
+ if (WSAGetLastError () != WSAEINVAL && winsock2_active)
- fhs->fixup_before_fork_exec (GetCurrentProcessId ());
- if (winsock2_active)
- fhs->fixup_after_fork (hMainProc);
- return get_io_handle () == (HANDLE) INVALID_SOCKET;
+ fhs->fixup_after_fork (hMainProc);
+ if (WSAGetLastError () != WSAEINVAL)
+ return get_io_handle () == (HANDLE) INVALID_SOCKET;
+ debug_printf ("WSADuplicateSocket failed, trying DuplicateHandle");
/* We don't call fhandler_base::dup here since that requires to
have winsock called from fhandler_base and it creates only
inheritable sockets which is wrong for winsock2. */
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Developer mailto:email@example.com
Red Hat, Inc.
More information about the Cygwin-developers