diff options
Diffstat (limited to 'networking/ntpd.c')
-rw-r--r-- | networking/ntpd.c | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c index 3ed05ba29..e27dbaa6b 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c | |||
@@ -27,6 +27,23 @@ | |||
27 | * * | 27 | * * |
28 | *********************************************************************** | 28 | *********************************************************************** |
29 | */ | 29 | */ |
30 | |||
31 | //usage:#define ntpd_trivial_usage | ||
32 | //usage: "[-dnqNw"IF_FEATURE_NTPD_SERVER("l")"] [-S PROG] [-p PEER]..." | ||
33 | //usage:#define ntpd_full_usage "\n\n" | ||
34 | //usage: "NTP client/server\n" | ||
35 | //usage: "\nOptions:" | ||
36 | //usage: "\n -d Verbose" | ||
37 | //usage: "\n -n Do not daemonize" | ||
38 | //usage: "\n -q Quit after clock is set" | ||
39 | //usage: "\n -N Run at high priority" | ||
40 | //usage: "\n -w Do not set time (only query peers), implies -n" | ||
41 | //usage: IF_FEATURE_NTPD_SERVER( | ||
42 | //usage: "\n -l Run as server on port 123" | ||
43 | //usage: ) | ||
44 | //usage: "\n -S PROG Run PROG after stepping time, stratum change, and every 11 mins" | ||
45 | //usage: "\n -p PEER Obtain time from PEER (may be repeated)" | ||
46 | |||
30 | #include "libbb.h" | 47 | #include "libbb.h" |
31 | #include <math.h> | 48 | #include <math.h> |
32 | #include <netinet/ip.h> /* For IPTOS_LOWDELAY definition */ | 49 | #include <netinet/ip.h> /* For IPTOS_LOWDELAY definition */ |
@@ -238,6 +255,8 @@ enum { | |||
238 | OPT_p = (1 << 5), | 255 | OPT_p = (1 << 5), |
239 | OPT_S = (1 << 6), | 256 | OPT_S = (1 << 6), |
240 | OPT_l = (1 << 7) * ENABLE_FEATURE_NTPD_SERVER, | 257 | OPT_l = (1 << 7) * ENABLE_FEATURE_NTPD_SERVER, |
258 | /* We hijack some bits for other purposes */ | ||
259 | OPT_qq = (1 << 8), | ||
241 | }; | 260 | }; |
242 | 261 | ||
243 | struct globals { | 262 | struct globals { |
@@ -1930,15 +1949,18 @@ static NOINLINE void ntp_init(char **argv) | |||
1930 | setpriority(PRIO_PROCESS, 0, -15); | 1949 | setpriority(PRIO_PROCESS, 0, -15); |
1931 | 1950 | ||
1932 | /* If network is up, syncronization occurs in ~10 seconds. | 1951 | /* If network is up, syncronization occurs in ~10 seconds. |
1933 | * We give "ntpd -q" a full minute to finish, then we exit. | 1952 | * We give "ntpd -q" 10 seconds to get first reply, |
1953 | * then another 50 seconds to finish syncing. | ||
1934 | * | 1954 | * |
1935 | * I tested ntpd 4.2.6p1 and apparently it never exits | 1955 | * I tested ntpd 4.2.6p1 and apparently it never exits |
1936 | * (will try forever), but it does not feel right. | 1956 | * (will try forever), but it does not feel right. |
1937 | * The goal of -q is to act like ntpdate: set time | 1957 | * The goal of -q is to act like ntpdate: set time |
1938 | * after a reasonably small period of polling, or fail. | 1958 | * after a reasonably small period of polling, or fail. |
1939 | */ | 1959 | */ |
1940 | if (opts & OPT_q) | 1960 | if (opts & OPT_q) { |
1941 | alarm(60); | 1961 | option_mask32 |= OPT_qq; |
1962 | alarm(10); | ||
1963 | } | ||
1942 | 1964 | ||
1943 | bb_signals(0 | 1965 | bb_signals(0 |
1944 | | (1 << SIGTERM) | 1966 | | (1 << SIGTERM) |
@@ -2065,6 +2087,15 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) | |||
2065 | #endif | 2087 | #endif |
2066 | for (; nfds != 0 && j < i; j++) { | 2088 | for (; nfds != 0 && j < i; j++) { |
2067 | if (pfd[j].revents /* & (POLLIN|POLLERR)*/) { | 2089 | if (pfd[j].revents /* & (POLLIN|POLLERR)*/) { |
2090 | /* | ||
2091 | * At init, alarm was set to 10 sec. | ||
2092 | * Now we did get a reply. | ||
2093 | * Increase timeout to 50 seconds to finish syncing. | ||
2094 | */ | ||
2095 | if (option_mask32 & OPT_qq) { | ||
2096 | option_mask32 &= ~OPT_qq; | ||
2097 | alarm(50); | ||
2098 | } | ||
2068 | nfds--; | 2099 | nfds--; |
2069 | recv_and_process_peer_pkt(idx2peer[j]); | 2100 | recv_and_process_peer_pkt(idx2peer[j]); |
2070 | gettime1900d(); /* sets G.cur_time */ | 2101 | gettime1900d(); /* sets G.cur_time */ |