File: namedxfer-timer-patch.diff

package info (click to toggle)
bind 1%3A8.4.6-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 19,752 kB
  • ctags: 22,385
  • sloc: ansic: 159,091; sh: 19,593; perl: 14,224; makefile: 5,554; yacc: 2,475; cpp: 2,154; csh: 848; awk: 753; tcl: 674; lex: 423; fortran: 240
file content (159 lines) | stat: -rw-r--r-- 4,341 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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;
 				}