| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ntptimeset.c,v 1.5 2006/06/11 19:34:21 kardel Exp $ */ | | 1 | /* $NetBSD: ntptimeset.c,v 1.6 2010/04/02 21:33:14 christos Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * ntptimeset - get/set the time via ntp | | 4 | * ntptimeset - get/set the time via ntp |
5 | * | | 5 | * |
6 | * GOAL: | | 6 | * GOAL: |
7 | * The goal of ntptime is to set the current time on system startup | | 7 | * The goal of ntptime is to set the current time on system startup |
8 | * to the best possible time using the network very wisely. It is assumed | | 8 | * to the best possible time using the network very wisely. It is assumed |
9 | * that after a resonable time has been sett then ntp daemon will | | 9 | * that after a resonable time has been sett then ntp daemon will |
10 | * maintain it. | | 10 | * maintain it. |
11 | * | | 11 | * |
12 | * PROBLEM DOMAIN: | | 12 | * PROBLEM DOMAIN: |
13 | * We have three sets of issues related to acheiving the goal. The first | | 13 | * We have three sets of issues related to acheiving the goal. The first |
14 | * issue is using the network when normal traffic is happening or when | | 14 | * issue is using the network when normal traffic is happening or when |
| @@ -1495,26 +1495,27 @@ clock_select(void) | | | @@ -1495,26 +1495,27 @@ clock_select(void) |
1495 | } | | 1495 | } |
1496 | | | 1496 | |
1497 | | | 1497 | |
1498 | /* | | 1498 | /* |
1499 | * set_local_clock -- handle setting the local clock or displaying info. | | 1499 | * set_local_clock -- handle setting the local clock or displaying info. |
1500 | */ | | 1500 | */ |
1501 | static void | | 1501 | static void |
1502 | set_local_clock(void) | | 1502 | set_local_clock(void) |
1503 | { | | 1503 | { |
1504 | register int i; | | 1504 | register int i; |
1505 | register struct server *server; | | 1505 | register struct server *server; |
1506 | time_t tmp; | | 1506 | time_t tmp; |
1507 | double dtemp; | | 1507 | double dtemp; |
| | | 1508 | const char *p; |
1508 | | | 1509 | |
1509 | /* | | 1510 | /* |
1510 | * if setting time then print final analysis | | 1511 | * if setting time then print final analysis |
1511 | */ | | 1512 | */ |
1512 | if (set_time) | | 1513 | if (set_time) |
1513 | analysis(1); | | 1514 | analysis(1); |
1514 | | | 1515 | |
1515 | /* | | 1516 | /* |
1516 | * pick a clock | | 1517 | * pick a clock |
1517 | */ | | 1518 | */ |
1518 | server = clock_select(); | | 1519 | server = clock_select(); |
1519 | | | 1520 | |
1520 | /* | | 1521 | /* |
| @@ -1556,26 +1557,28 @@ set_local_clock(void) | | | @@ -1556,26 +1557,28 @@ set_local_clock(void) |
1556 | /* | | 1557 | /* |
1557 | * set the clock | | 1558 | * set the clock |
1558 | * XXX: Examine the more flexible approach used by ntpdate. | | 1559 | * XXX: Examine the more flexible approach used by ntpdate. |
1559 | * Note that a design consideration here is that we sometimes | | 1560 | * Note that a design consideration here is that we sometimes |
1560 | * _want_ to step the clock by a _huge_ amount in either | | 1561 | * _want_ to step the clock by a _huge_ amount in either |
1561 | * direction, because the local clock is completely bogus. | | 1562 | * direction, because the local clock is completely bogus. |
1562 | * This condition must be recognized and dealt with, so | | 1563 | * This condition must be recognized and dealt with, so |
1563 | * that we always get a good time when this completes. | | 1564 | * that we always get a good time when this completes. |
1564 | * -- jhutz+@cmu.edu, 16-Aug-1999 | | 1565 | * -- jhutz+@cmu.edu, 16-Aug-1999 |
1565 | */ | | 1566 | */ |
1566 | LFPTOD(&server->offset, dtemp); | | 1567 | LFPTOD(&server->offset, dtemp); |
1567 | step_systime(dtemp); | | 1568 | step_systime(dtemp); |
1568 | time(&tmp); | | 1569 | time(&tmp); |
| | | 1570 | if ((p = ctime(&tmp)) == NULL) |
| | | 1571 | p = "?"; |
1569 | fprintf(stdout,"Time set to %.20s [%s %s %ld/%ld]\n", | | 1572 | fprintf(stdout,"Time set to %.20s [%s %s %ld/%ld]\n", |
1570 | ctime(&tmp)+4, | | 1573 | ctime(&tmp)+4, |
1571 | ntoa(&server->srcadr), | | 1574 | ntoa(&server->srcadr), |
1572 | lfptoa(&server->offset, 7), | | 1575 | lfptoa(&server->offset, 7), |
1573 | total_xmit, total_recv); | | 1576 | total_xmit, total_recv); |
1574 | exit(0); | | 1577 | exit(0); |
1575 | } | | 1578 | } |
1576 | | | 1579 | |
1577 | | | 1580 | |
1578 | /* | | 1581 | /* |
1579 | * findserver - find a server in the list given its address | | 1582 | * findserver - find a server in the list given its address |
1580 | */ | | 1583 | */ |
1581 | static struct server * | | 1584 | static struct server * |