Deleted Added
full compact
master.c (19093) master.c (30642)
1/*-
2 * Copyright (c) 1985, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 18 unchanged lines hidden (view full) ---

27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
1/*-
2 * Copyright (c) 1985, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 18 unchanged lines hidden (view full) ---

27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35#if 0
35static char sccsid[] = "@(#)master.c 8.1 (Berkeley) 6/6/93";
36static char sccsid[] = "@(#)master.c 8.1 (Berkeley) 6/6/93";
37#endif
38static const char rcsid[] =
39 "$Id$";
36#endif /* not lint */
37
40#endif /* not lint */
41
38#ifdef sgi
39#ident "$Revision: 1.1.1.1 $"
40#endif
41
42#include "globals.h"
43#include <sys/file.h>
44#include <sys/types.h>
45#include <sys/times.h>
46#include <setjmp.h>
47#ifdef sgi
48#include <sys/schedctl.h>
49#endif /* sgi */

--- 95 unchanged lines hidden (view full) ---

145
146 synch(0L);
147
148 for (ntp = nettab; ntp != NULL; ntp = ntp->next) {
149 to.tsp_type = TSP_LOOP;
150 to.tsp_vers = TSPVERSION;
151 to.tsp_seq = sequence++;
152 to.tsp_hopcnt = MAX_HOPCNT;
42#include "globals.h"
43#include <sys/file.h>
44#include <sys/types.h>
45#include <sys/times.h>
46#include <setjmp.h>
47#ifdef sgi
48#include <sys/schedctl.h>
49#endif /* sgi */

--- 95 unchanged lines hidden (view full) ---

145
146 synch(0L);
147
148 for (ntp = nettab; ntp != NULL; ntp = ntp->next) {
149 to.tsp_type = TSP_LOOP;
150 to.tsp_vers = TSPVERSION;
151 to.tsp_seq = sequence++;
152 to.tsp_hopcnt = MAX_HOPCNT;
153 (void)strcpy(to.tsp_name, hostname);
153 (void)strncpy(to.tsp_name, hostname,
154 sizeof to.tsp_name-1);
155 to.tsp_name[sizeof to.tsp_name-1] = '\0';
154 bytenetorder(&to);
155 if (sendto(sock, (char *)&to,
156 sizeof(struct tsp), 0,
157 (struct sockaddr*)&ntp->dest_addr,
158 sizeof(ntp->dest_addr)) < 0) {
159 trace_sendto_err(ntp->dest_addr.sin_addr);
160 }
161 }

--- 12 unchanged lines hidden (view full) ---

174
175 case TSP_SETDATE:
176 /*
177 * XXX check to see it is from ourself
178 */
179#ifdef sgi
180 (void)cftime(newdate, "%D %T", &msg->tsp_time.tv_sec);
181#else
156 bytenetorder(&to);
157 if (sendto(sock, (char *)&to,
158 sizeof(struct tsp), 0,
159 (struct sockaddr*)&ntp->dest_addr,
160 sizeof(ntp->dest_addr)) < 0) {
161 trace_sendto_err(ntp->dest_addr.sin_addr);
162 }
163 }

--- 12 unchanged lines hidden (view full) ---

176
177 case TSP_SETDATE:
178 /*
179 * XXX check to see it is from ourself
180 */
181#ifdef sgi
182 (void)cftime(newdate, "%D %T", &msg->tsp_time.tv_sec);
183#else
182 (void)strcpy(newdate, ctime(&msg->tsp_time.tv_sec));
184 (void)strncpy(newdate, ctime(&msg->tsp_time.tv_sec),
185 sizeof newdate-1);
186 newdate[sizeof newdate-1] = '\0';
183#endif /* sgi */
184 if (!good_host_name(msg->tsp_name)) {
185 syslog(LOG_NOTICE,
186 "attempted date change by %s to %s",
187 msg->tsp_name, newdate);
188 spreadtime();
189 break;
190 }

--- 4 unchanged lines hidden (view full) ---

195 break;
196
197 case TSP_SETDATEREQ:
198 if (!fromnet || fromnet->status != MASTER)
199 break;
200#ifdef sgi
201 (void)cftime(newdate, "%D %T", &msg->tsp_time.tv_sec);
202#else
187#endif /* sgi */
188 if (!good_host_name(msg->tsp_name)) {
189 syslog(LOG_NOTICE,
190 "attempted date change by %s to %s",
191 msg->tsp_name, newdate);
192 spreadtime();
193 break;
194 }

--- 4 unchanged lines hidden (view full) ---

199 break;
200
201 case TSP_SETDATEREQ:
202 if (!fromnet || fromnet->status != MASTER)
203 break;
204#ifdef sgi
205 (void)cftime(newdate, "%D %T", &msg->tsp_time.tv_sec);
206#else
203 (void)strcpy(newdate, ctime(&msg->tsp_time.tv_sec));
207 (void)strncpy(newdate, ctime(&msg->tsp_time.tv_sec),
208 sizeof newdate-1);
209 newdate[sizeof newdate-1] = '\0';
204#endif /* sgi */
205 htp = findhost(msg->tsp_name);
206 if (htp == 0) {
207 syslog(LOG_ERR,
208 "attempted SET DATEREQ by uncontrolled %s to %s",
209 msg->tsp_name, newdate);
210 break;
211 }

--- 31 unchanged lines hidden (view full) ---

243 case TSP_ELECTION:
244 if (!fromnet)
245 break;
246 if (fromnet->status == MASTER) {
247 pollingtime = 0;
248 (void)addmach(msg->tsp_name, &from,fromnet);
249 }
250 taddr = from;
210#endif /* sgi */
211 htp = findhost(msg->tsp_name);
212 if (htp == 0) {
213 syslog(LOG_ERR,
214 "attempted SET DATEREQ by uncontrolled %s to %s",
215 msg->tsp_name, newdate);
216 break;
217 }

--- 31 unchanged lines hidden (view full) ---

249 case TSP_ELECTION:
250 if (!fromnet)
251 break;
252 if (fromnet->status == MASTER) {
253 pollingtime = 0;
254 (void)addmach(msg->tsp_name, &from,fromnet);
255 }
256 taddr = from;
251 (void)strcpy(tname, msg->tsp_name);
257 (void)strncpy(tname, msg->tsp_name, sizeof tname-1);
258 tname[sizeof tname-1] = '\0';
252 to.tsp_type = TSP_QUIT;
259 to.tsp_type = TSP_QUIT;
253 (void)strcpy(to.tsp_name, hostname);
260 (void)strncpy(to.tsp_name, hostname,
261 sizeof to.tsp_name-1);
262 to.tsp_name[sizeof to.tsp_name-1] = '\0';
254 answer = acksend(&to, &taddr, tname,
255 TSP_ACK, 0, 1);
256 if (answer == NULL) {
257 syslog(LOG_ERR, "election error by %s",
258 tname);
259 }
260 break;
261
262 case TSP_CONFLICT:
263 /*
264 * After a network partition, there can be
265 * more than one master: the first slave to
266 * come up will notify here the situation.
267 */
268 if (!fromnet || fromnet->status != MASTER)
269 break;
263 answer = acksend(&to, &taddr, tname,
264 TSP_ACK, 0, 1);
265 if (answer == NULL) {
266 syslog(LOG_ERR, "election error by %s",
267 tname);
268 }
269 break;
270
271 case TSP_CONFLICT:
272 /*
273 * After a network partition, there can be
274 * more than one master: the first slave to
275 * come up will notify here the situation.
276 */
277 if (!fromnet || fromnet->status != MASTER)
278 break;
270 (void)strcpy(to.tsp_name, hostname);
279 (void)strncpy(to.tsp_name, hostname,
280 sizeof to.tsp_name-1);
281 to.tsp_name[sizeof to.tsp_name-1] = '\0';
271
272 /* The other master often gets into the same state,
273 * with boring results if we stay at it forever.
274 */
275 ntp = fromnet; /* (acksend() can leave fromnet=0 */
276 for (i = 0; i < 3; i++) {
277 to.tsp_type = TSP_RESOLVE;
282
283 /* The other master often gets into the same state,
284 * with boring results if we stay at it forever.
285 */
286 ntp = fromnet; /* (acksend() can leave fromnet=0 */
287 for (i = 0; i < 3; i++) {
288 to.tsp_type = TSP_RESOLVE;
278 (void)strcpy(to.tsp_name, hostname);
289 (void)strncpy(to.tsp_name, hostname,
290 sizeof to.tsp_name-1);
291 to.tsp_name[sizeof to.tsp_name-1] = '\0';
279 answer = acksend(&to, &ntp->dest_addr,
280 ANYADDR, TSP_MASTERACK,
281 ntp, 0);
282 if (!answer)
283 break;
284 htp = addmach(answer->tsp_name,&from,ntp);
285 to.tsp_type = TSP_QUIT;
286 msg = acksend(&to, &htp->addr, htp->name,

--- 28 unchanged lines hidden (view full) ---

315 || !strcmp(msg->tsp_name, hostname))
316 break;
317 /*
318 * We should not have received this from a net
319 * we are master on. There must be two masters.
320 */
321 htp = addmach(msg->tsp_name, &from,fromnet);
322 to.tsp_type = TSP_QUIT;
292 answer = acksend(&to, &ntp->dest_addr,
293 ANYADDR, TSP_MASTERACK,
294 ntp, 0);
295 if (!answer)
296 break;
297 htp = addmach(answer->tsp_name,&from,ntp);
298 to.tsp_type = TSP_QUIT;
299 msg = acksend(&to, &htp->addr, htp->name,

--- 28 unchanged lines hidden (view full) ---

328 || !strcmp(msg->tsp_name, hostname))
329 break;
330 /*
331 * We should not have received this from a net
332 * we are master on. There must be two masters.
333 */
334 htp = addmach(msg->tsp_name, &from,fromnet);
335 to.tsp_type = TSP_QUIT;
323 (void)strcpy(to.tsp_name, hostname);
336 (void)strncpy(to.tsp_name, hostname,
337 sizeof to.tsp_name-1);
338 to.tsp_name[sizeof to.tsp_name-1] = '\0';
324 answer = acksend(&to, &htp->addr, htp->name,
325 TSP_ACK, 0, 1);
326 if (!answer) {
327 syslog(LOG_WARNING,
328 "loop breakage: no reply from %s=%s to QUIT",
329 htp->name, inet_ntoa(htp->addr.sin_addr));
330 (void)remmach(htp);
331 }

--- 27 unchanged lines hidden (view full) ---

359static void
360mchgdate(msg)
361 struct tsp *msg;
362{
363 char tname[MAXHOSTNAMELEN];
364 char olddate[32];
365 struct timeval otime, ntime;
366
339 answer = acksend(&to, &htp->addr, htp->name,
340 TSP_ACK, 0, 1);
341 if (!answer) {
342 syslog(LOG_WARNING,
343 "loop breakage: no reply from %s=%s to QUIT",
344 htp->name, inet_ntoa(htp->addr.sin_addr));
345 (void)remmach(htp);
346 }

--- 27 unchanged lines hidden (view full) ---

374static void
375mchgdate(msg)
376 struct tsp *msg;
377{
378 char tname[MAXHOSTNAMELEN];
379 char olddate[32];
380 struct timeval otime, ntime;
381
367 (void)strcpy(tname, msg->tsp_name);
382 (void)strncpy(tname, msg->tsp_name, sizeof tname-1);
383 tname[sizeof tname-1] = '\0';
368
369 xmit(TSP_DATEACK, msg->tsp_seq, &from);
370
384
385 xmit(TSP_DATEACK, msg->tsp_seq, &from);
386
371 (void)strcpy(olddate, date());
387 (void)strncpy(olddate, date(), sizeof olddate-1);
388 olddate[sizeof olddate-1] = '\0';
372
373 /* adjust time for residence on the queue */
374 (void)gettimeofday(&otime, 0);
375 adj_msg_time(msg,&otime);
376
377 timevalsub(&ntime, &msg->tsp_time, &otime);
378 if (ntime.tv_sec < MAXADJ && ntime.tv_sec > -MAXADJ) {
379 /*

--- 118 unchanged lines hidden (view full) ---

498 struct tsp *answer;
499
500/* Do not listen to the consensus after forcing the time. This is because
501 * the consensus takes a while to reach the time we are dictating.
502 */
503 dictate = 2;
504 for (htp = self.l_fwd; htp != &self; htp = htp->l_fwd) {
505 to.tsp_type = TSP_SETTIME;
389
390 /* adjust time for residence on the queue */
391 (void)gettimeofday(&otime, 0);
392 adj_msg_time(msg,&otime);
393
394 timevalsub(&ntime, &msg->tsp_time, &otime);
395 if (ntime.tv_sec < MAXADJ && ntime.tv_sec > -MAXADJ) {
396 /*

--- 118 unchanged lines hidden (view full) ---

515 struct tsp *answer;
516
517/* Do not listen to the consensus after forcing the time. This is because
518 * the consensus takes a while to reach the time we are dictating.
519 */
520 dictate = 2;
521 for (htp = self.l_fwd; htp != &self; htp = htp->l_fwd) {
522 to.tsp_type = TSP_SETTIME;
506 (void)strcpy(to.tsp_name, hostname);
523 (void)strncpy(to.tsp_name, hostname, sizeof to.tsp_name-1);
524 to.tsp_name[sizeof to.tsp_name-1] = '\0';
507 (void)gettimeofday(&to.tsp_time, 0);
508 answer = acksend(&to, &htp->addr, htp->name,
509 TSP_ACK, 0, htp->noanswer);
510 if (answer == 0) {
511 /* We client does not respond, then we have
512 * just wasted lots of time on it.
513 */
514 syslog(LOG_WARNING,

--- 267 unchanged lines hidden (view full) ---

782 /*
783 * If we are stable, send our time to the slave.
784 * Do not go crazy if the date has been changed.
785 */
786 (void)gettimeofday(&now, 0);
787 if (now.tv_sec >= fromnet->slvwait.tv_sec+3
788 || now.tv_sec < fromnet->slvwait.tv_sec) {
789 to.tsp_type = TSP_SETTIME;
525 (void)gettimeofday(&to.tsp_time, 0);
526 answer = acksend(&to, &htp->addr, htp->name,
527 TSP_ACK, 0, htp->noanswer);
528 if (answer == 0) {
529 /* We client does not respond, then we have
530 * just wasted lots of time on it.
531 */
532 syslog(LOG_WARNING,

--- 267 unchanged lines hidden (view full) ---

800 /*
801 * If we are stable, send our time to the slave.
802 * Do not go crazy if the date has been changed.
803 */
804 (void)gettimeofday(&now, 0);
805 if (now.tv_sec >= fromnet->slvwait.tv_sec+3
806 || now.tv_sec < fromnet->slvwait.tv_sec) {
807 to.tsp_type = TSP_SETTIME;
790 (void)strcpy(to.tsp_name, hostname);
808 (void)strncpy(to.tsp_name, hostname, sizeof to.tsp_name-1);
809 to.tsp_name[sizeof to.tsp_name-1] = '\0';
791 (void)gettimeofday(&to.tsp_time, 0);
792 answer = acksend(&to, &htp->addr,
793 htp->name, TSP_ACK,
794 0, htp->noanswer);
795 if (answer) {
796 htp->need_set = 0;
797 } else {
798 syslog(LOG_WARNING,

--- 109 unchanged lines hidden ---
810 (void)gettimeofday(&to.tsp_time, 0);
811 answer = acksend(&to, &htp->addr,
812 htp->name, TSP_ACK,
813 0, htp->noanswer);
814 if (answer) {
815 htp->need_set = 0;
816 } else {
817 syslog(LOG_WARNING,

--- 109 unchanged lines hidden ---