]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Fixes from bug #411 Marc de la Gueronniere
authorDanny Mayer <mayer@ntp.org>
Sun, 16 Oct 2005 22:43:40 +0000 (18:43 -0400)
committerDanny Mayer <mayer@ntp.org>
Sun, 16 Oct 2005 22:43:40 +0000 (18:43 -0400)
bk: 4352d79c6x9w4GaXBU89HLeOkvqS0Q

ntpd/ntp_intres.c

index 4a480b882fa1c385106385f99534da463141ab0a..18b349e60439cea2ac8c417391d895cbbb9923b8 100644 (file)
@@ -169,6 +169,21 @@ struct ntp_res_c_pkt {             /* Control packet: */
 };
 
 
+static void    resolver_exit P((int));
+
+/*
+ * Call here instead of just exiting
+ */
+
+static void resolver_exit (int code)
+{
+#ifdef SYS_WINNT
+       ExitThread (code);      /* Just to kill the thread not the process */
+#else
+       exit (code);            /* fill the forked process */
+#endif
+}
+
 /*
  * ntp_res_recv: Process an answer from the resolver
  */
@@ -212,7 +227,7 @@ ntp_intres(void)
                if (!authistrusted(req_keyid)) {
                        msyslog(LOG_ERR, "invalid request keyid %08x",
                            req_keyid );
-                       exit(1);
+                       resolver_exit(1);
                }
        }
 
@@ -224,7 +239,7 @@ ntp_intres(void)
        if ((in = fopen(req_file, "r")) == NULL) {
                msyslog(LOG_ERR, "can't open configuration file %s: %m",
                        req_file);
-               exit(1);
+               resolver_exit(1);
        }
        readconf(in, req_file);
        (void) fclose(in);
@@ -243,11 +258,7 @@ ntp_intres(void)
         */
        doconfigure(1);
        if (confentries == NULL) {
-#if defined SYS_WINNT
-               ExitThread(0);  /* Don't want to kill whole NT process */
-#else
-               exit(0);        /* done that quick */
-#endif
+               resolver_exit(0);
        }
        
        /*
@@ -263,7 +274,7 @@ ntp_intres(void)
 
        for (;;) {
                if (confentries == NULL)
-                   exit(0);
+                   resolver_exit(0);
 
                checkparent();
 
@@ -285,7 +296,7 @@ ntp_intres(void)
                                msyslog(LOG_INFO, "config_timer: 0->%d", config_timer);
 #endif
                        doconfigure(0);
-                       continue;
+                       continue; 
                }
 #ifndef SYS_WINNT
                /*
@@ -346,7 +357,7 @@ checkparent(void)
         */
        if (getppid() == 1) {
                msyslog(LOG_INFO, "parent died before we finished, exiting");
-               exit(0);
+               resolver_exit(0);
        }
 #endif /* SYS_WINNT && SYS_VXWORKS*/
 }
@@ -459,13 +470,13 @@ findhostaddr(
 
        checkparent();          /* make sure our guy is still running */
 
-       if (entry->ce_name != NULL && SOCKNUL(&entry->peer_store)) {
+       if (entry->ce_name != NULL && !SOCKNUL(&entry->peer_store)) {
                /* HMS: Squawk? */
                msyslog(LOG_ERR, "findhostaddr: both ce_name and ce_peeraddr are defined...");
                return 1;
        }
 
-        if (entry->ce_name == NULL && !SOCKNUL(&entry->peer_store)) {
+        if (entry->ce_name == NULL && SOCKNUL(&entry->peer_store)) {
                msyslog(LOG_ERR, "findhostaddr: both ce_name and ce_peeraddr are undefined!");
                return 0;
        }
@@ -482,7 +493,7 @@ findhostaddr(
                /*
                 * If the IPv6 stack is not available look only for IPv4 addresses
                 */
-               if (isc_net_probeipv6() == ISC_R_SUCCESS)
+               if (isc_net_probeipv6() != ISC_R_SUCCESS)
                        hints.ai_family = AF_INET;
 
                error = getaddrinfo(entry->ce_name, NULL, &hints, &addr);
@@ -516,7 +527,7 @@ findhostaddr(
                 * If the resolver is in use, see if the failure is
                 * temporary.  If so, return success.
                 */
-               if (h_errno == TRY_AGAIN)
+               if (error == EAI_AGAIN)
                    return (1);
                return (0);
        }
@@ -545,29 +556,28 @@ openntp(void)
 {
        struct addrinfo hints;
        struct addrinfo *addrResult;
+       const char *localhost = "127.0.0.1";    /* Use IPv6 loopback */
 
        if (sockfd >= 0)
            return;
 
        memset(&hints, 0, sizeof(hints));
-       hints.ai_family = AF_UNSPEC;
 
        /*
-        * If the IPv6 stack is not available look only for IPv4 addresses
+        * For now only bother with IPv4
         */
-       if (isc_net_probeipv6() == ISC_R_SUCCESS)
-               hints.ai_family = AF_INET;
+       hints.ai_family = AF_INET;
 
        hints.ai_socktype = SOCK_DGRAM;
-       if (getaddrinfo(NULL, "ntp", &hints, &addrResult)!=0) {
+       if (getaddrinfo(localhost, "ntp", &hints, &addrResult)!=0) {
                msyslog(LOG_ERR, "getaddrinfo failed: %m");
-               exit(1);
+               resolver_exit(1);
        }
        sockfd = socket(addrResult->ai_family, addrResult->ai_socktype, 0);
 
        if (sockfd == -1) {
                msyslog(LOG_ERR, "socket() failed: %m");
-               exit(1);
+               resolver_exit(1);
        }
 
        /*
@@ -577,13 +587,13 @@ openntp(void)
 #if defined(O_NONBLOCK)
        if (fcntl(sockfd, F_SETFL, O_NONBLOCK) == -1) {
                msyslog(LOG_ERR, "fcntl(O_NONBLOCK) failed: %m");
-               exit(1);
+               resolver_exit(1);
        }
 #else
 #if defined(FNDELAY)
        if (fcntl(sockfd, F_SETFL, FNDELAY) == -1) {
                msyslog(LOG_ERR, "fcntl(FNDELAY) failed: %m");
-               exit(1);
+               resolver_exit(1);
        }
 #else
 # include "Bletch: NEED NON BLOCKING IO"
@@ -594,13 +604,13 @@ openntp(void)
                int on = 1;
                if (ioctlsocket(sockfd,FIONBIO,(u_long *) &on) == SOCKET_ERROR) {
                        msyslog(LOG_ERR, "ioctlsocket(FIONBIO) fails: %m");
-                       exit(1); /* Windows NT - set socket in non-blocking mode */
+                       resolver_exit(1); /* Windows NT - set socket in non-blocking mode */
                }
        }
 #endif /* SYS_WINNT */
        if (connect(sockfd, addrResult->ai_addr, addrResult->ai_addrlen) == -1) {
                msyslog(LOG_ERR, "openntp: connect() failed: %m");
-               exit(1);
+               resolver_exit(1);
        }
        freeaddrinfo(addrResult);
 }
@@ -628,7 +638,7 @@ request(
 
        checkparent();          /* make sure our guy is still running */
 
-       if (sockfd < 0)
+       if (sockfd == INVALID_SOCKET)
            openntp();
        
 #ifdef SYS_WINNT
@@ -664,7 +674,7 @@ request(
        /* Make sure mbz_itemsize <= sizeof reqpkt.data */
        if (sizeof(struct conf_peer) > sizeof (reqpkt.data)) {
                msyslog(LOG_ERR, "Bletch: conf_peer is too big for reqpkt.data!");
-               exit(1);
+               resolver_exit(1);
        }
        memmove(reqpkt.data, (char *)conf, sizeof(struct conf_peer));
        reqpkt.keyid = htonl(req_keyid);
@@ -972,7 +982,7 @@ readconf(
                                msyslog(LOG_ERR,
                                        "tokenizing error in file `%s', quitting",
                                        name);
-                               exit(1);
+                               resolver_exit(1);
                        }
                }
 
@@ -981,7 +991,7 @@ readconf(
                                msyslog(LOG_ERR,
                                        "format error for integer token `%s', file `%s', quitting",
                                        token[i], name);
-                               exit(1);
+                               resolver_exit(1);
                        }
                }
 
@@ -990,27 +1000,27 @@ readconf(
                    intval[TOK_HMODE] != MODE_BROADCAST) {
                        msyslog(LOG_ERR, "invalid mode (%ld) in file %s",
                                intval[TOK_HMODE], name);
-                       exit(1);
+                       resolver_exit(1);
                }
 
                if (intval[TOK_VERSION] > NTP_VERSION ||
                    intval[TOK_VERSION] < NTP_OLDVERSION) {
                        msyslog(LOG_ERR, "invalid version (%ld) in file %s",
                                intval[TOK_VERSION], name);
-                       exit(1);
+                       resolver_exit(1);
                }
                if (intval[TOK_MINPOLL] < NTP_MINPOLL ||
                    intval[TOK_MINPOLL] > NTP_MAXPOLL) {
                        msyslog(LOG_ERR, "invalid MINPOLL value (%ld) in file %s",
                                intval[TOK_MINPOLL], name);
-                       exit(1);
+                       resolver_exit(1);
                }
 
                if (intval[TOK_MAXPOLL] < NTP_MINPOLL ||
                    intval[TOK_MAXPOLL] > NTP_MAXPOLL) {
                        msyslog(LOG_ERR, "invalid MAXPOLL value (%ld) in file %s",
                                intval[TOK_MAXPOLL], name);
-                       exit(1);
+                       resolver_exit(1);
                }
 
                if ((intval[TOK_FLAGS] & ~(FLAG_AUTHENABLE | FLAG_PREFER |
@@ -1018,7 +1028,7 @@ readconf(
                    != 0) {
                        msyslog(LOG_ERR, "invalid flags (%ld) in file %s",
                                intval[TOK_FLAGS], name);
-                       exit(1);
+                       resolver_exit(1);
                }
 
                flags = 0;