slave.c (19093) | slave.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[] = "@(#)slave.c 8.1 (Berkeley) 6/6/93"; | 36static char sccsid[] = "@(#)slave.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 <setjmp.h> 44#include "pathnames.h" 45 46extern jmp_buf jmpenv; 47extern int Mflag; 48extern int justquit; 49 --- 96 unchanged lines hidden (view full) --- 146 if (trace) 147 fprintf(fd, "Looking for loops\n"); 148 for (ntp = nettab; ntp != NULL; ntp = ntp->next) { 149 if (ntp->status == MASTER) { 150 to.tsp_type = TSP_LOOP; 151 to.tsp_vers = TSPVERSION; 152 to.tsp_seq = sequence++; 153 to.tsp_hopcnt = MAX_HOPCNT; | 42#include "globals.h" 43#include <setjmp.h> 44#include "pathnames.h" 45 46extern jmp_buf jmpenv; 47extern int Mflag; 48extern int justquit; 49 --- 96 unchanged lines hidden (view full) --- 146 if (trace) 147 fprintf(fd, "Looking for loops\n"); 148 for (ntp = nettab; ntp != NULL; ntp = ntp->next) { 149 if (ntp->status == MASTER) { 150 to.tsp_type = TSP_LOOP; 151 to.tsp_vers = TSPVERSION; 152 to.tsp_seq = sequence++; 153 to.tsp_hopcnt = MAX_HOPCNT; |
154 (void)strcpy(to.tsp_name, hostname); | 154 (void)strncpy(to.tsp_name, hostname, 155 sizeof to.tsp_name-1); 156 to.tsp_name[sizeof to.tsp_name-1] = '\0'; |
155 bytenetorder(&to); 156 if (sendto(sock, (char *)&to, 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 } 162 } --- 97 unchanged lines hidden (view full) --- 260#ifdef sgi 261 (void)cftime(newdate, "%D %T", &msg->tsp_time.tv_sec); 262 (void)cftime(olddate, "%D %T", &otime.tv_sec); 263#else 264 /* 265 * the following line is necessary due to syslog 266 * calling ctime() which clobbers the static buffer 267 */ | 157 bytenetorder(&to); 158 if (sendto(sock, (char *)&to, 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 } 164 } --- 97 unchanged lines hidden (view full) --- 262#ifdef sgi 263 (void)cftime(newdate, "%D %T", &msg->tsp_time.tv_sec); 264 (void)cftime(olddate, "%D %T", &otime.tv_sec); 265#else 266 /* 267 * the following line is necessary due to syslog 268 * calling ctime() which clobbers the static buffer 269 */ |
268 (void)strcpy(olddate, date()); 269 (void)strcpy(newdate, ctime(&msg->tsp_time.tv_sec)); | 270 (void)strncpy(olddate, date(), sizeof olddate-1); 271 olddate[sizeof olddate-1] = '\0'; 272 (void)strncpy(newdate, ctime(&msg->tsp_time.tv_sec), 273 sizeof newdate-1); 274 newdate[sizeof newdate-1] = '\0'; |
270#endif /* sgi */ 271 272 if (!good_host_name(msg->tsp_name)) { 273 syslog(LOG_NOTICE, 274 "attempted time setting by untrusted %s to %s", 275 msg->tsp_name, newdate); 276 suppress(&from, msg->tsp_name, fromnet); 277 break; --- 74 unchanged lines hidden (view full) --- 352 (void)gettimeofday(&ntime, 0); 353 electiontime = ntime.tv_sec + delay2; 354 break; 355 356 case TSP_SETDATE: 357#ifdef sgi 358 (void)cftime(newdate, "%D %T", &msg->tsp_time.tv_sec); 359#else | 275#endif /* sgi */ 276 277 if (!good_host_name(msg->tsp_name)) { 278 syslog(LOG_NOTICE, 279 "attempted time setting by untrusted %s to %s", 280 msg->tsp_name, newdate); 281 suppress(&from, msg->tsp_name, fromnet); 282 break; --- 74 unchanged lines hidden (view full) --- 357 (void)gettimeofday(&ntime, 0); 358 electiontime = ntime.tv_sec + delay2; 359 break; 360 361 case TSP_SETDATE: 362#ifdef sgi 363 (void)cftime(newdate, "%D %T", &msg->tsp_time.tv_sec); 364#else |
360 (void)strcpy(newdate, ctime(&msg->tsp_time.tv_sec)); | 365 (void)strncpy(newdate, ctime(&msg->tsp_time.tv_sec), 366 sizeof newdate-1); 367 newdate[sizeof newdate-1] = '\0'; |
361#endif /* sgi */ 362 schgdate(msg, newdate); 363 break; 364 365 case TSP_SETDATEREQ: 366 if (fromnet->status != MASTER) 367 break; 368#ifdef sgi 369 (void)cftime(newdate, "%D %T", &msg->tsp_time.tv_sec); 370#else | 368#endif /* sgi */ 369 schgdate(msg, newdate); 370 break; 371 372 case TSP_SETDATEREQ: 373 if (fromnet->status != MASTER) 374 break; 375#ifdef sgi 376 (void)cftime(newdate, "%D %T", &msg->tsp_time.tv_sec); 377#else |
371 (void)strcpy(newdate, ctime(&msg->tsp_time.tv_sec)); | 378 (void)strncpy(newdate, ctime(&msg->tsp_time.tv_sec), 379 sizeof newdate-1); 380 newdate[sizeof newdate-1] = '\0'; |
372#endif /* sgi */ 373 htp = findhost(msg->tsp_name); 374 if (0 == htp) { 375 syslog(LOG_WARNING, 376 "DATEREQ from uncontrolled machine"); 377 break; 378 } 379 if (!htp->good) { --- 37 unchanged lines hidden (view full) --- 417 */ 418 to.tsp_type = TSP_REFUSE; 419 } else { 420 cadr.s_addr = from.sin_addr.s_addr; 421 to.tsp_type = TSP_ACCEPT; 422 refusetime = ntime.tv_sec + 30; 423 } 424 taddr = from; | 381#endif /* sgi */ 382 htp = findhost(msg->tsp_name); 383 if (0 == htp) { 384 syslog(LOG_WARNING, 385 "DATEREQ from uncontrolled machine"); 386 break; 387 } 388 if (!htp->good) { --- 37 unchanged lines hidden (view full) --- 426 */ 427 to.tsp_type = TSP_REFUSE; 428 } else { 429 cadr.s_addr = from.sin_addr.s_addr; 430 to.tsp_type = TSP_ACCEPT; 431 refusetime = ntime.tv_sec + 30; 432 } 433 taddr = from; |
425 (void)strcpy(tname, msg->tsp_name); 426 (void)strcpy(to.tsp_name, hostname); | 434 (void)strncpy(tname, msg->tsp_name, 435 sizeof tname-1); 436 tname[sizeof tname-1] = '\0'; 437 (void)strncpy(to.tsp_name, hostname, 438 sizeof to.tsp_name-1); 439 to.tsp_name[sizeof to.tsp_name-1] = '\0'; |
427 answerdelay(); 428 if (!acksend(&to, &taddr, tname, 429 TSP_ACK, 0, 0)) 430 syslog(LOG_WARNING, 431 "no answer from candidate %s\n", 432 tname); 433 434 } else { /* fromnet->status == MASTER */ 435 htp = addmach(msg->tsp_name, &from,fromnet); 436 to.tsp_type = TSP_QUIT; | 440 answerdelay(); 441 if (!acksend(&to, &taddr, tname, 442 TSP_ACK, 0, 0)) 443 syslog(LOG_WARNING, 444 "no answer from candidate %s\n", 445 tname); 446 447 } else { /* fromnet->status == MASTER */ 448 htp = addmach(msg->tsp_name, &from,fromnet); 449 to.tsp_type = TSP_QUIT; |
437 (void)strcpy(to.tsp_name, hostname); | 450 (void)strncpy(to.tsp_name, hostname, 451 sizeof to.tsp_name-1); 452 to.tsp_name[sizeof to.tsp_name-1] = '\0'; |
438 if (!acksend(&to, &htp->addr, htp->name, 439 TSP_ACK, 0, htp->noanswer)) { 440 syslog(LOG_ERR, 441 "no reply from %s to ELECTION-QUIT", 442 htp->name); 443 (void)remmach(htp); 444 } 445 } 446 break; 447 448 case TSP_CONFLICT: 449 if (fromnet->status != MASTER) 450 break; 451 /* 452 * After a network partition, there can be 453 * more than one master: the first slave to 454 * come up will notify here the situation. 455 */ | 453 if (!acksend(&to, &htp->addr, htp->name, 454 TSP_ACK, 0, htp->noanswer)) { 455 syslog(LOG_ERR, 456 "no reply from %s to ELECTION-QUIT", 457 htp->name); 458 (void)remmach(htp); 459 } 460 } 461 break; 462 463 case TSP_CONFLICT: 464 if (fromnet->status != MASTER) 465 break; 466 /* 467 * After a network partition, there can be 468 * more than one master: the first slave to 469 * come up will notify here the situation. 470 */ |
456 (void)strcpy(to.tsp_name, hostname); | 471 (void)strncpy(to.tsp_name, hostname, 472 sizeof to.tsp_name-1); 473 to.tsp_name[sizeof to.tsp_name-1] = '\0'; |
457 458 /* The other master often gets into the same state, 459 * with boring results. 460 */ 461 ntp = fromnet; /* (acksend() can leave fromnet=0 */ 462 for (tries = 0; tries < 3; tries++) { 463 to.tsp_type = TSP_RESOLVE; 464 answer = acksend(&to, &ntp->dest_addr, --- 17 unchanged lines hidden (view full) --- 482 483 case TSP_MSITE: 484 if (!slavenet) 485 break; 486 taddr = from; 487 to.tsp_type = TSP_MSITEREQ; 488 to.tsp_vers = TSPVERSION; 489 to.tsp_seq = 0; | 474 475 /* The other master often gets into the same state, 476 * with boring results. 477 */ 478 ntp = fromnet; /* (acksend() can leave fromnet=0 */ 479 for (tries = 0; tries < 3; tries++) { 480 to.tsp_type = TSP_RESOLVE; 481 answer = acksend(&to, &ntp->dest_addr, --- 17 unchanged lines hidden (view full) --- 499 500 case TSP_MSITE: 501 if (!slavenet) 502 break; 503 taddr = from; 504 to.tsp_type = TSP_MSITEREQ; 505 to.tsp_vers = TSPVERSION; 506 to.tsp_seq = 0; |
490 (void)strcpy(to.tsp_name, hostname); | 507 (void)strncpy(to.tsp_name, hostname, 508 sizeof to.tsp_name-1); 509 to.tsp_name[sizeof to.tsp_name-1] = '\0'; |
491 answer = acksend(&to, &slavenet->dest_addr, 492 ANYADDR, TSP_ACK, 493 slavenet, 0); 494 if (answer != NULL 495 && good_host_name(answer->tsp_name)) { 496 setmaster(answer); 497 to.tsp_type = TSP_ACK; | 510 answer = acksend(&to, &slavenet->dest_addr, 511 ANYADDR, TSP_ACK, 512 slavenet, 0); 513 if (answer != NULL 514 && good_host_name(answer->tsp_name)) { 515 setmaster(answer); 516 to.tsp_type = TSP_ACK; |
498 (void)strcpy(to.tsp_name, answer->tsp_name); | 517 (void)strncpy(to.tsp_name, answer->tsp_name, 518 sizeof to.tsp_name-1); 519 to.tsp_name[sizeof to.tsp_name-1] = '\0'; |
499 bytenetorder(&to); 500 if (sendto(sock, (char *)&to, 501 sizeof(struct tsp), 0, | 520 bytenetorder(&to); 521 if (sendto(sock, (char *)&to, 522 sizeof(struct tsp), 0, |
502 (struct sockaddr*)&taddr, sizeof(taddr)) < 0) { | 523 (struct sockaddr*)&taddr, 524 sizeof(taddr)) < 0) { |
503 trace_sendto_err(taddr.sin_addr); 504 } 505 } 506 break; 507 508 case TSP_MSITEREQ: 509 break; 510 --- 28 unchanged lines hidden (view full) --- 539 for (tries = 0; tries < 3; tries++) { 540 to.tsp_type = TSP_RESOLVE; 541 answer = acksend(&to, &ntp->dest_addr, 542 ANYADDR, TSP_MASTERACK, 543 ntp,0); 544 if (answer == NULL) 545 break; 546 taddr = from; | 525 trace_sendto_err(taddr.sin_addr); 526 } 527 } 528 break; 529 530 case TSP_MSITEREQ: 531 break; 532 --- 28 unchanged lines hidden (view full) --- 561 for (tries = 0; tries < 3; tries++) { 562 to.tsp_type = TSP_RESOLVE; 563 answer = acksend(&to, &ntp->dest_addr, 564 ANYADDR, TSP_MASTERACK, 565 ntp,0); 566 if (answer == NULL) 567 break; 568 taddr = from; |
547 (void)strcpy(tname, answer->tsp_name); | 569 (void)strncpy(tname, answer->tsp_name, 570 sizeof tname-1); 571 tname[sizeof tname-1] = '\0'; |
548 to.tsp_type = TSP_QUIT; | 572 to.tsp_type = TSP_QUIT; |
549 (void)strcpy(to.tsp_name, hostname); | 573 (void)strncpy(to.tsp_name, hostname, 574 sizeof to.tsp_name-1); 575 to.tsp_name[sizeof to.tsp_name-1] = '\0'; |
550 if (!acksend(&to, &taddr, tname, 551 TSP_ACK, 0, 1)) { 552 syslog(LOG_ERR, 553 "no reply from %s to slave LOOP-QUIT", 554 tname); 555 } else { 556 electiontime = 0; 557 } --- 36 unchanged lines hidden (view full) --- 594 answer = acksend(&to, &ntp->dest_addr, 595 ANYADDR, TSP_MASTERACK, 596 ntp,0); 597 if (!answer) 598 break; 599 htp = addmach(answer->tsp_name, 600 &from,ntp); 601 to.tsp_type = TSP_QUIT; | 576 if (!acksend(&to, &taddr, tname, 577 TSP_ACK, 0, 1)) { 578 syslog(LOG_ERR, 579 "no reply from %s to slave LOOP-QUIT", 580 tname); 581 } else { 582 electiontime = 0; 583 } --- 36 unchanged lines hidden (view full) --- 620 answer = acksend(&to, &ntp->dest_addr, 621 ANYADDR, TSP_MASTERACK, 622 ntp,0); 623 if (!answer) 624 break; 625 htp = addmach(answer->tsp_name, 626 &from,ntp); 627 to.tsp_type = TSP_QUIT; |
602 (void)strcpy(to.tsp_name, hostname); | 628 (void)strncpy(to.tsp_name, hostname, 629 sizeof to.tsp_name-1); 630 to.tsp_name[sizeof to.tsp_name-1] = '\0'; |
603 if (!acksend(&to,&htp->addr,htp->name, 604 TSP_ACK, 0, htp->noanswer)) { 605 syslog(LOG_ERR, 606 "no reply from %s to master LOOP-QUIT", 607 htp->name); 608 (void)remmach(htp); 609 } 610 } --- 19 unchanged lines hidden (view full) --- 630static void 631setmaster(msg) 632 struct tsp *msg; 633{ 634 if (slavenet 635 && (slavenet != old_slavenet 636 || strcmp(msg->tsp_name, master_name) 637 || old_status != status)) { | 631 if (!acksend(&to,&htp->addr,htp->name, 632 TSP_ACK, 0, htp->noanswer)) { 633 syslog(LOG_ERR, 634 "no reply from %s to master LOOP-QUIT", 635 htp->name); 636 (void)remmach(htp); 637 } 638 } --- 19 unchanged lines hidden (view full) --- 658static void 659setmaster(msg) 660 struct tsp *msg; 661{ 662 if (slavenet 663 && (slavenet != old_slavenet 664 || strcmp(msg->tsp_name, master_name) 665 || old_status != status)) { |
638 (void)strcpy(master_name, msg->tsp_name); | 666 (void)strncpy(master_name, msg->tsp_name, 667 sizeof master_name-1); 668 master_name[sizeof master_name-1] = '\0'; |
639 old_slavenet = slavenet; 640 old_status = status; 641 642 if (status & MASTER) { 643 syslog(LOG_NOTICE, "submaster to %s", master_name); 644 if (trace) 645 fprintf(fd, "submaster to %s\n", master_name); 646 --- 31 unchanged lines hidden (view full) --- 678 msg->tsp_name, newdate); 679 680 /* adjust time for residence on the queue */ 681 (void)gettimeofday(&otime, 0); 682 adj_msg_time(msg, &otime); 683 684 to.tsp_type = TSP_SETDATEREQ; 685 to.tsp_time = msg->tsp_time; | 669 old_slavenet = slavenet; 670 old_status = status; 671 672 if (status & MASTER) { 673 syslog(LOG_NOTICE, "submaster to %s", master_name); 674 if (trace) 675 fprintf(fd, "submaster to %s\n", master_name); 676 --- 31 unchanged lines hidden (view full) --- 708 msg->tsp_name, newdate); 709 710 /* adjust time for residence on the queue */ 711 (void)gettimeofday(&otime, 0); 712 adj_msg_time(msg, &otime); 713 714 to.tsp_type = TSP_SETDATEREQ; 715 to.tsp_time = msg->tsp_time; |
686 (void)strcpy(to.tsp_name, hostname); | 716 (void)strncpy(to.tsp_name, hostname, sizeof to.tsp_name-1); 717 to.tsp_name[sizeof to.tsp_name-1] = '\0'; |
687 if (!acksend(&to, &slavenet->dest_addr, 688 ANYADDR, TSP_DATEACK, 689 slavenet, 0)) 690 return; /* no answer */ 691 692 xmit(TSP_DATEACK, seq, &taddr); 693} 694 --- 21 unchanged lines hidden --- | 718 if (!acksend(&to, &slavenet->dest_addr, 719 ANYADDR, TSP_DATEACK, 720 slavenet, 0)) 721 return; /* no answer */ 722 723 xmit(TSP_DATEACK, seq, &taddr); 724} 725 --- 21 unchanged lines hidden --- |