]> arthur.barton.de Git - netatalk.git/blobdiff - etc/cnid_dbd/usockfd.c
cnid_metad: fix tsockfd_create() return value on error
[netatalk.git] / etc / cnid_dbd / usockfd.c
index d9dadb5b9828a879d447897a4acf8e8e060a177a..269c6575beefbc8e5f5026d6d090425892a40d62 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
 #include <sys/un.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
-
-#ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
-#endif /* HAVE_SYS_TYPES_H */
-#ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
-#endif /* HAVE_SYS_TIME_H */
-
 
 #include <atalk/logger.h>
+#include <atalk/compat.h>
 #include "usockfd.h"
 
 #include <sys/select.h>
@@ -92,15 +85,15 @@ int tsockfd_create(char *host, char *port, int backlog)
     hints.ai_socktype = SOCK_STREAM;
 
     if ((ret = getaddrinfo(host, port, &hints, &servinfo)) != 0) {
-        LOG(log_error, logtype_default, "tsockfd_create: getaddrinfo: %s\n", gai_strerror(ret));
-        return 0;
+        LOG(log_error, logtype_cnid, "tsockfd_create: getaddrinfo: %s\n", gai_strerror(ret));
+        return -1;
     }
 
     /* create a socket */
     /* loop through all the results and bind to the first we can */
     for (p = servinfo; p != NULL; p = p->ai_next) {
         if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
-            LOG(log_info, logtype_default, "tsockfd_create: socket: %s", strerror(errno));
+            LOG(log_info, logtype_cnid, "tsockfd_create: socket: %s", strerror(errno));
             continue;
         }
 
@@ -124,13 +117,13 @@ int tsockfd_create(char *host, char *port, int backlog)
             
         if (bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
             close(sockfd);
-            LOG(log_info, logtype_default, "tsockfd_create: bind: %s\n", strerror(errno));
+            LOG(log_info, logtype_cnid, "tsockfd_create: bind: %s\n", strerror(errno));
             continue;
         }
 
         if (listen(sockfd, backlog) < 0) {
             close(sockfd);
-            LOG(log_info, logtype_default, "tsockfd_create: listen: %s\n", strerror(errno));
+            LOG(log_info, logtype_cnid, "tsockfd_create: listen: %s\n", strerror(errno));
             continue;
         }
 
@@ -139,7 +132,7 @@ int tsockfd_create(char *host, char *port, int backlog)
     }
 
     if (p == NULL)  {
-        LOG(log_error, logtype_default, "tsockfd_create: no suitable network config %s:%s", host, port);
+        LOG(log_error, logtype_cnid, "tsockfd_create: no suitable network config %s:%s", host, port);
         freeaddrinfo(servinfo);
         return -1;
     }
@@ -155,7 +148,6 @@ int usockfd_check(int sockfd, const sigset_t *sigset)
     socklen_t size;
     fd_set readfds;
     int ret;
-    struct timeval tv;
      
     FD_ZERO(&readfds);
     FD_SET(sockfd, &readfds);
@@ -177,10 +169,6 @@ int usockfd_check(int sockfd, const sigset_t *sigset)
                 strerror(errno));
             return -1;
         }
-        if (setnonblock(fd, 1) != 0) {
-            LOG(log_error, logtype_cnid, "setnonblock: %s", strerror(errno));
-            return -1;
-        }
         return fd;
     } else
         return 0;