This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

connect() hangs on a listen()ing AF_UNIX socket


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.

Christian


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]