Index: named-xfer.c
===================================================================
RCS file: /proj/cvs/prod/bind8/src/bin/named-xfer/named-xfer.c,v
retrieving revision 8.144
diff -u -r8.144 named-xfer.c
--- named-xfer.c	27 Aug 2004 00:23:16 -0000	8.144
+++ named-xfer.c	27 Aug 2004 00:39:15 -0000
@@ -186,8 +186,10 @@
 extern long pathconf __P((const char *path, int name));	/* XXX */
 # endif
 
+static const char	setitimerStr[] = "setitimer: %m";
 
-static	struct zoneinfo	zone;		/* zone information */
+static struct zoneinfo	zone;		/* zone information */
+static struct itimerval	ival, zeroival;
 
 static	char		*ddtfilename = NULL,
 			*ddtfile = NULL;
@@ -197,7 +199,7 @@
 			*domain;	/* domain being xfered */
 
 static	int		quiet = 0,
-			read_interrupted = 0,
+			net_interrupted = 0,
 			curclass,
 			domain_len;		/* strlen(domain) */
 
@@ -212,12 +214,12 @@
 static	int		getzone(struct zoneinfo *, u_int32_t),
 			print_output(struct zoneinfo *, u_int32_t, 
 				     u_char *, int, u_char *, int),
-			netread(int, char *, int, int, const char *),
+			netread(int, char *, int, const char *),
 			writemsg(int, const u_char *, int);
 static int		ixfr_log(const u_char *msg, int len, int *delete,
 				 FILE *file, struct sockaddr *sin,
 				 u_int32_t *serial_no, int *);
-static	SIG_FN		read_alarm(void);
+static	SIG_FN		net_alarm(void);
 static	SIG_FN		term_handler(void);
 static	const char	*soa_zinfo(struct zoneinfo *, u_char *, u_char*),
 			*tsig_rcode(int);
@@ -332,6 +334,9 @@
 	int class = C_IN;
 	int n;
 
+	ival = zeroival;
+	ival.it_value.tv_sec = 30;	/* used to be XFER_TIMER (120) */
+
 	/*
 	 * Ensure stdin, stdout and stderr are open.
 	 */
@@ -985,7 +990,7 @@
 	u_int bufsize = *bufsizep;
 	u_int len;
 	
-	if (netread(fd, (char *)buf, INT16SZ, XFER_TIMER, sa_ntoa(sin)) < 0)
+	if (netread(fd, (char *)buf, INT16SZ, sa_ntoa(sin)) < 0)
 		return (0);
 
 	if ((len = ns_get16(buf)) == 0)
@@ -1001,7 +1006,7 @@
 		*bufsizep = bufsize = len;
 	}
 
-	if (netread(fd, (char *)buf, len, XFER_TIMER, sa_ntoa(sin)) < 0) 
+	if (netread(fd, (char *)buf, len, sa_ntoa(sin)) < 0) 
 		return (0);
 
 #ifdef DEBUG
@@ -1123,7 +1128,7 @@
 #endif
 #ifdef POSIX_SIGNALS
 	memset(&sv, 0, sizeof sv);
-	sv.sa_handler = (SIG_FN (*)()) read_alarm;
+	sv.sa_handler = (SIG_FN (*)()) net_alarm;
 	/* SA_ONSTACK isn't recommended for strict POSIX code */
 	/* is it absolutely necessary? */
 	/* sv.sa_flags = SA_ONSTACK; */
@@ -1135,7 +1140,7 @@
 	(void) sigaction(SIGTERM, &sv, &osv);
 #else
 	memset(&sv, 0, sizeof sv);
-	sv.sv_handler = read_alarm;
+	sv.sv_handler = net_alarm;
 	sv.sv_mask = ~0;
 	(void) sigvec(SIGALRM, &sv, &osv);
 	memset(&sv, 0, sizeof sv);
@@ -1201,7 +1206,19 @@
 		}
 		lprintf(2, "connecting to server #%d %s\n",
 			cnt + 1, sa_ntoa(sa));
+#ifndef _WIN32
+		if (setitimer(ITIMER_REAL, &ival, NULL) < 0) {
+			syslog(LOG_INFO, setitimerStr);
+			error++;
+			(void) my_close(s);
+			continue;
+		}
+#endif
 		if (connect(s, sa, sa_slen(sa)) < 0) {
+			if (errno == EINTR && !net_interrupted) {
+				/* wasn't a timeout, ignore. */
+				goto try_again;
+			}
 			if (src != NULL) {
 				lprintf(2, "connect failed, trying w/o -x/-X");
 				src = NULL;
@@ -1217,6 +1234,14 @@
 			(void) my_close(s);
 			continue;
 		}	
+#ifndef _WIN32
+		if (setitimer(ITIMER_REAL, &zeroival, NULL) < 0) {
+			syslog(LOG_INFO, setitimerStr);
+			error++;
+			(void) my_close(s);
+			continue;
+		}
+#endif
 
 		query_type = (methode == ISIXFR && was_ixfr == 0) ?
 			      T_IXFR : T_SOA;
@@ -2005,22 +2030,17 @@
  * used for a read timer
  */
 static SIG_FN
-read_alarm() {
-	read_interrupted = 1;
+net_alarm() {
+	net_interrupted = 1;
 }
  
 static int
-netread(int fd, char *buf, int len, int timeout, const char *remote) {
-	static const char setitimerStr[] = "setitimer: %m";
-	struct itimerval ival, zeroival;
+netread(int fd, char *buf, int len, const char *remote) {
 	int n;
 #if defined(NETREAD_BROKEN)
 	int retries = 0;
 #endif
 
-	memset(&zeroival, 0, sizeof zeroival);
-	ival = zeroival;
-	ival.it_value.tv_sec = timeout;
 	while (len > 0) {
 #ifndef _WIN32
 		if (setitimer(ITIMER_REAL, &ival, NULL) < 0) {
@@ -2052,7 +2072,7 @@
 				return (-1);
 			}
 			if (errno == EINTR) {
-				if (!read_interrupted) {
+				if (!net_interrupted) {
 					/* It wasn't a timeout; ignore it. */
 					continue;
 				}
