connect() hangs on a listen()ing AF_UNIX socket
Corinna Vinschen
corinna-cygwin@cygwin.com
Thu Aug 21 16:44:00 GMT 2014
On Aug 21 18:16, Christian Franke wrote:
> Corinna Vinschen wrote (in thread "[ITP] libsuexec 1.0"):
> >Postfix for Cygwin would be *so* nice. Sigh. ...
>
> Due to the following problem, Postfix hangs during startup (and blocks any
> possible "[ITP] postfix ..."):
>
> If a AF_UNIX socket is in listen()ing state, a client connect() should
> succeed immediately. On Cygwin, connect() waits until the server site
> accept()s the connection.
>
> Testcase:
>
> #include <stdio.h>
> #include <unistd.h>
> #include <sys/socket.h>
> #include <sys/un.h>
>
> int main()
> {
> sockaddr_un sa = {AF_UNIX, "testsocket"};
> unlink(sa.sun_path);
>
> int sd1 = socket(AF_UNIX, SOCK_STREAM, 0);
> if (sd1 < 0) {
> perror("socket"); return 1;
> }
> if (bind(sd1, (sockaddr*) &sa, sizeof(sa))) {
> perror("bind"); return 1;
> }
> if (listen(sd1, 10) < 0) {
> perror("listen"); return 1;
> }
>
> int sd2 = socket(AF_UNIX, SOCK_STREAM, 0);
> if (sd2 < 0) {
> perror("socket"); return 1;
> }
> printf("connecting to %s ...\n", sa.sun_path);
>
> // Cygwin hangs here:
> if (connect(sd2, (sockaddr*) &sa, sizeof(sa))) {
> perror("connect"); return 1;
> }
>
> // Linux & friends arrive here:
> printf("connected\n");
> return 0;
> }
>
>
> This is likely because fhandler_socket::af_local_connect() waits for some
> secret. Sending it in af_local_accept() is too late in this case.
>
> Unfortunately the event handling of postfix relies on the correct behavior
> and there is possibly no easy workaround.
Off the top of my head I don't see one inside the Cygwin DLL :(
The problem is that the package exchange at the start of an
accept/connect is required to be able to exchange credentials. This in
turn is required for getpeereid and the SO_PEERCRED socket option which
is utilized at least by sshd.
Would it help to patch postfix for Cygwin to use a local-only AF_INET
socket at this point instead?
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20140821/61bf141e/attachment.sig>
More information about the Cygwin
mailing list