slave.c (30642) | slave.c (30830) |
---|---|
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 --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35#if 0 36static char sccsid[] = "@(#)slave.c 8.1 (Berkeley) 6/6/93"; 37#endif 38static const char rcsid[] = | 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 --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35#if 0 36static char sccsid[] = "@(#)slave.c 8.1 (Berkeley) 6/6/93"; 37#endif 38static const char rcsid[] = |
39 "$Id$"; | 39 "$Id: slave.c,v 1.3 1997/10/22 06:19:48 charnier Exp $"; |
40#endif /* not lint */ 41 42#include "globals.h" 43#include <setjmp.h> 44#include "pathnames.h" 45 46extern jmp_buf jmpenv; 47extern int Mflag; --- 98 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; | 40#endif /* not lint */ 41 42#include "globals.h" 43#include <setjmp.h> 44#include "pathnames.h" 45 46extern jmp_buf jmpenv; 47extern int Mflag; --- 98 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)strncpy(to.tsp_name, hostname, 155 sizeof to.tsp_name-1); 156 to.tsp_name[sizeof to.tsp_name-1] = '\0'; | 154 (void)strcpy(to.tsp_name, hostname); |
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 */ | 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 */ |
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'; | 268 (void)strcpy(olddate, date()); 269 (void)strcpy(newdate, ctime(&msg->tsp_time.tv_sec)); |
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 | 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 |
365 (void)strncpy(newdate, ctime(&msg->tsp_time.tv_sec), 366 sizeof newdate-1); 367 newdate[sizeof newdate-1] = '\0'; | 360 (void)strcpy(newdate, ctime(&msg->tsp_time.tv_sec)); |
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 | 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 |
378 (void)strncpy(newdate, ctime(&msg->tsp_time.tv_sec), 379 sizeof newdate-1); 380 newdate[sizeof newdate-1] = '\0'; | 371 (void)strcpy(newdate, ctime(&msg->tsp_time.tv_sec)); |
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; | 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; |
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'; | 425 (void)strcpy(tname, msg->tsp_name); 426 (void)strcpy(to.tsp_name, hostname); |
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; | 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; |
450 (void)strncpy(to.tsp_name, hostname, 451 sizeof to.tsp_name-1); 452 to.tsp_name[sizeof to.tsp_name-1] = '\0'; | 437 (void)strcpy(to.tsp_name, hostname); |
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 */ | 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 */ |
471 (void)strncpy(to.tsp_name, hostname, 472 sizeof to.tsp_name-1); 473 to.tsp_name[sizeof to.tsp_name-1] = '\0'; | 456 (void)strcpy(to.tsp_name, hostname); |
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; | 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; |
507 (void)strncpy(to.tsp_name, hostname, 508 sizeof to.tsp_name-1); 509 to.tsp_name[sizeof to.tsp_name-1] = '\0'; | 490 (void)strcpy(to.tsp_name, hostname); |
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; | 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; |
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'; | 498 (void)strcpy(to.tsp_name, answer->tsp_name); |
520 bytenetorder(&to); 521 if (sendto(sock, (char *)&to, 522 sizeof(struct tsp), 0, 523 (struct sockaddr*)&taddr, | 499 bytenetorder(&to); 500 if (sendto(sock, (char *)&to, 501 sizeof(struct tsp), 0, 502 (struct sockaddr*)&taddr, |
524 sizeof(taddr)) < 0) { | 503 sizeof(taddr)) < 0) { |
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; | 504 trace_sendto_err(taddr.sin_addr); 505 } 506 } 507 break; 508 509 case TSP_MSITEREQ: 510 break; 511 --- 28 unchanged lines hidden (view full) --- 540 for (tries = 0; tries < 3; tries++) { 541 to.tsp_type = TSP_RESOLVE; 542 answer = acksend(&to, &ntp->dest_addr, 543 ANYADDR, TSP_MASTERACK, 544 ntp,0); 545 if (answer == NULL) 546 break; 547 taddr = from; |
569 (void)strncpy(tname, answer->tsp_name, 570 sizeof tname-1); 571 tname[sizeof tname-1] = '\0'; | 548 (void)strcpy(tname, answer->tsp_name); |
572 to.tsp_type = TSP_QUIT; | 549 to.tsp_type = TSP_QUIT; |
573 (void)strncpy(to.tsp_name, hostname, 574 sizeof to.tsp_name-1); 575 to.tsp_name[sizeof to.tsp_name-1] = '\0'; | 550 (void)strcpy(to.tsp_name, hostname); |
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; | 551 if (!acksend(&to, &taddr, tname, 552 TSP_ACK, 0, 1)) { 553 syslog(LOG_ERR, 554 "no reply from %s to slave LOOP-QUIT", 555 tname); 556 } else { 557 electiontime = 0; 558 } --- 36 unchanged lines hidden (view full) --- 595 answer = acksend(&to, &ntp->dest_addr, 596 ANYADDR, TSP_MASTERACK, 597 ntp,0); 598 if (!answer) 599 break; 600 htp = addmach(answer->tsp_name, 601 &from,ntp); 602 to.tsp_type = TSP_QUIT; |
628 (void)strncpy(to.tsp_name, hostname, 629 sizeof to.tsp_name-1); 630 to.tsp_name[sizeof to.tsp_name-1] = '\0'; | 603 (void)strcpy(to.tsp_name, hostname); |
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)) { | 604 if (!acksend(&to,&htp->addr,htp->name, 605 TSP_ACK, 0, htp->noanswer)) { 606 syslog(LOG_ERR, 607 "no reply from %s to master LOOP-QUIT", 608 htp->name); 609 (void)remmach(htp); 610 } 611 } --- 19 unchanged lines hidden (view full) --- 631static void 632setmaster(msg) 633 struct tsp *msg; 634{ 635 if (slavenet 636 && (slavenet != old_slavenet 637 || strcmp(msg->tsp_name, master_name) 638 || old_status != status)) { |
666 (void)strncpy(master_name, msg->tsp_name, 667 sizeof master_name-1); 668 master_name[sizeof master_name-1] = '\0'; | 639 (void)strcpy(master_name, msg->tsp_name); |
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; | 640 old_slavenet = slavenet; 641 old_status = status; 642 643 if (status & MASTER) { 644 syslog(LOG_NOTICE, "submaster to %s", master_name); 645 if (trace) 646 fprintf(fd, "submaster to %s\n", master_name); 647 --- 31 unchanged lines hidden (view full) --- 679 msg->tsp_name, newdate); 680 681 /* adjust time for residence on the queue */ 682 (void)gettimeofday(&otime, 0); 683 adj_msg_time(msg, &otime); 684 685 to.tsp_type = TSP_SETDATEREQ; 686 to.tsp_time = msg->tsp_time; |
716 (void)strncpy(to.tsp_name, hostname, sizeof to.tsp_name-1); 717 to.tsp_name[sizeof to.tsp_name-1] = '\0'; | 687 (void)strcpy(to.tsp_name, hostname); |
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 --- | 688 if (!acksend(&to, &slavenet->dest_addr, 689 ANYADDR, TSP_DATEACK, 690 slavenet, 0)) 691 return; /* no answer */ 692 693 xmit(TSP_DATEACK, seq, &taddr); 694} 695 --- 21 unchanged lines hidden --- |