- Set "listener" to -1 after we close it so that the error-handler
authorWayne Davison <wayned@samba.org>
Thu, 16 Sep 2004 17:09:46 +0000 (17:09 +0000)
committerWayne Davison <wayned@samba.org>
Thu, 16 Sep 2004 17:09:46 +0000 (17:09 +0000)
  doesn't try to re-close it.
- Set blocking I/O before the second (final) connect() call.

socket.c

index 29fb2dc..8d21735 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -687,7 +687,7 @@ static int socketpair_tcp(int fd[2])
        struct sockaddr_in sock;
        struct sockaddr_in sock2;
        socklen_t socklen = sizeof sock;
-       int connect_done = 0;
+       int errno_save, connect_done = 0;
 
        fd[0] = fd[1] = listener = -1;
 
@@ -727,24 +727,28 @@ static int socketpair_tcp(int fd[2])
                goto failed;
 
        close(listener);
+       listener = -1;
+
+       set_blocking(fd[1]);
+
        if (connect_done == 0) {
                if (connect(fd[1], (struct sockaddr *)&sock, sizeof sock) != 0
                    && errno != EISCONN)
                        goto failed;
        }
 
-       set_blocking(fd[1]);
-
        /* all OK! */
        return 0;
 
  failed:
+       errno_save = errno;
        if (fd[0] != -1)
                close(fd[0]);
        if (fd[1] != -1)
                close(fd[1]);
        if (listener != -1)
                close(listener);
+       errno = errno_save;
        return -1;
 }