listen_on_socket: only hand out the socket fd when the complet func succeede events
authorMichael Adam <obnox@samba.org>
Thu, 27 Aug 2009 11:51:37 +0000 (13:51 +0200)
committerMichael Adam <obnox@samba.org>
Thu, 27 Aug 2009 11:51:37 +0000 (13:51 +0200)
and log the success at level INFO

Michael

sockets.c

index 09adc5c50e3a97974785628e76985b993165864f..a8e4b6917d324647ad3b60d7833b749e84bc59f9 100644 (file)
--- a/sockets.c
+++ b/sockets.c
@@ -10,7 +10,7 @@
 
 int listen_on_socket(const char *node, const char *service, int *sockfd)
 {
-       int ret;
+       int ret, fd;
        struct addrinfo hints;
        struct addrinfo *result = NULL;
 
@@ -37,23 +37,26 @@ int listen_on_socket(const char *node, const char *service, int *sockfd)
                                  strerror(errno)));
                goto done;
        }
-       *sockfd = ret;
+       fd = ret;
        DEBUG(DEBUG_DEBUG, ("socket: created\n"));
 
-       ret = bind(*sockfd, result->ai_addr, result->ai_addrlen);
+       ret = bind(fd, result->ai_addr, result->ai_addrlen);
        if (ret != 0) {
                DEBUG(DEBUG_ERR, ("error calling bind: %s\n", strerror(errno)));
                goto done;
        }
        DEBUG(DEBUG_DEBUG, ("bind: bound socket to %s:%s\n", node, service));
 
-       ret = listen(*sockfd, 0);
+       ret = listen(fd, 0);
        if (ret != 0) {
                DEBUG(DEBUG_ERR, ("error calling listen: %s\n",
                                  strerror(errno)));
                goto done;
        }
-       DEBUG(DEBUG_DEBUG, ("listen: ok\n"));
+       DEBUG(DEBUG_INFO, ("listening on %s:%s (socket fd %d)\n", node, service,
+                          fd));
+
+       *sockfd = fd;
 
 done:
        if (result != NULL) {