]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: set invalid socket fd by macro
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 24 Mar 2014 12:48:28 +0000 (13:48 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 25 Mar 2014 10:34:31 +0000 (11:34 +0100)
ntp_io.c

index 0e7aa737f4a0e62aa34a04b94281d0f714e9e1c6..46287817e2b95a476c5714667a732449b14a7995 100644 (file)
--- a/ntp_io.c
+++ b/ntp_io.c
@@ -39,6 +39,8 @@
 #include "conf.h"
 #include "util.h"
 
+#define INVALID_SOCK_FD -1
+
 union sockaddr_in46 {
   struct sockaddr_in in4;
 #ifdef HAVE_IPV6
@@ -114,7 +116,7 @@ prepare_socket(int family)
   if (sock_fd < 0) {
     LOG(LOGS_ERR, LOGF_NtpIO, "Could not open %s NTP socket : %s",
         family == AF_INET ? "IPv4" : "IPv6", strerror(errno));
-    return -1;
+    return INVALID_SOCK_FD;
   }
 
   /* Close on exec */
@@ -213,7 +215,7 @@ prepare_socket(int family)
     LOG(LOGS_ERR, LOGF_NtpIO, "Could not bind %s NTP socket : %s",
         family == AF_INET ? "IPv4" : "IPv6", strerror(errno));
     close(sock_fd);
-    return -1;
+    return INVALID_SOCK_FD;
   }
 
   /* Register handler for read events on the socket */
@@ -244,17 +246,17 @@ NIO_Initialise(int family)
   if (family == IPADDR_UNSPEC || family == IPADDR_INET4)
     sock_fd4 = prepare_socket(AF_INET);
   else
-    sock_fd4 = -1;
+    sock_fd4 = INVALID_SOCK_FD;
 #ifdef HAVE_IPV6
   if (family == IPADDR_UNSPEC || family == IPADDR_INET6)
     sock_fd6 = prepare_socket(AF_INET6);
   else
-    sock_fd6 = -1;
+    sock_fd6 = INVALID_SOCK_FD;
 #endif
 
-  if (sock_fd4 < 0
+  if (sock_fd4 == INVALID_SOCK_FD
 #ifdef HAVE_IPV6
-      && sock_fd6 < 0
+      && sock_fd6 == INVALID_SOCK_FD
 #endif
       ) {
     LOG_FATAL(LOGF_NtpIO, "Could not open any NTP socket");
@@ -266,17 +268,17 @@ NIO_Initialise(int family)
 void
 NIO_Finalise(void)
 {
-  if (sock_fd4 >= 0) {
+  if (sock_fd4 != INVALID_SOCK_FD) {
     SCH_RemoveInputFileHandler(sock_fd4);
     close(sock_fd4);
   }
-  sock_fd4 = -1;
+  sock_fd4 = INVALID_SOCK_FD;
 #ifdef HAVE_IPV6
-  if (sock_fd6 >= 0) {
+  if (sock_fd6 != INVALID_SOCK_FD) {
     SCH_RemoveInputFileHandler(sock_fd6);
     close(sock_fd6);
   }
-  sock_fd6 = -1;
+  sock_fd6 = INVALID_SOCK_FD;
 #endif
   initialised = 0;
 }
@@ -435,7 +437,7 @@ send_packet(void *packet, int packetlen, NTP_Remote_Address *remote_addr)
       return;
   }
 
-  if (sock_fd < 0)
+  if (sock_fd == INVALID_SOCK_FD)
     return;
 
   iov.iov_base = packet;