};
+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
*/
if (!authistrusted(req_keyid)) {
msyslog(LOG_ERR, "invalid request keyid %08x",
req_keyid );
- exit(1);
+ resolver_exit(1);
}
}
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);
*/
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);
}
/*
for (;;) {
if (confentries == NULL)
- exit(0);
+ resolver_exit(0);
checkparent();
msyslog(LOG_INFO, "config_timer: 0->%d", config_timer);
#endif
doconfigure(0);
- continue;
+ continue;
}
#ifndef SYS_WINNT
/*
*/
if (getppid() == 1) {
msyslog(LOG_INFO, "parent died before we finished, exiting");
- exit(0);
+ resolver_exit(0);
}
#endif /* SYS_WINNT && SYS_VXWORKS*/
}
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;
}
/*
* 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);
* 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);
}
{
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);
}
/*
#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"
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);
}
checkparent(); /* make sure our guy is still running */
- if (sockfd < 0)
+ if (sockfd == INVALID_SOCKET)
openntp();
#ifdef SYS_WINNT
/* 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);
msyslog(LOG_ERR,
"tokenizing error in file `%s', quitting",
name);
- exit(1);
+ resolver_exit(1);
}
}
msyslog(LOG_ERR,
"format error for integer token `%s', file `%s', quitting",
token[i], name);
- exit(1);
+ resolver_exit(1);
}
}
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 |
!= 0) {
msyslog(LOG_ERR, "invalid flags (%ld) in file %s",
intval[TOK_FLAGS], name);
- exit(1);
+ resolver_exit(1);
}
flags = 0;