diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2014-03-23 15:06:38 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-03-23 18:34:51 +0100 |
commit | 504fe45f35bab29752d39cc2d39d2e8c43fe6eac (patch) | |
tree | 0ba9037b307bf01dd057881d1a72787481da8c6a | |
parent | f332617fbd9248f34cff183a2a4caa961730625d (diff) | |
download | busybox-w32-504fe45f35bab29752d39cc2d39d2e8c43fe6eac.tar.gz busybox-w32-504fe45f35bab29752d39cc2d39d2e8c43fe6eac.tar.bz2 busybox-w32-504fe45f35bab29752d39cc2d39d2e8c43fe6eac.zip |
ntpd: add optional support for /etc/ntp.conf
function old new delta
add_peers - 98 +98
packed_usage 29470 29511 +41
ntp_init 407 428 +21
pw_encrypt 14 27 +13
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/0 up/down: 173/0) Total: 173 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/Config.src | 8 | ||||
-rw-r--r-- | networking/ntpd.c | 35 |
2 files changed, 39 insertions, 4 deletions
diff --git a/networking/Config.src b/networking/Config.src index ca0ddcdd9..fbad7ecb2 100644 --- a/networking/Config.src +++ b/networking/Config.src | |||
@@ -664,6 +664,14 @@ config FEATURE_NTPD_SERVER | |||
664 | Make ntpd usable as a NTP server. If you disable this option | 664 | Make ntpd usable as a NTP server. If you disable this option |
665 | ntpd will be usable only as a NTP client. | 665 | ntpd will be usable only as a NTP client. |
666 | 666 | ||
667 | config FEATURE_NTPD_CONF | ||
668 | bool "Make ntpd understand /etc/ntp.conf" | ||
669 | default y | ||
670 | depends on NTPD | ||
671 | help | ||
672 | Make ntpd look in /etc/ntp.conf for peers. Only "server address" | ||
673 | is supported. | ||
674 | |||
667 | config PSCAN | 675 | config PSCAN |
668 | bool "pscan" | 676 | bool "pscan" |
669 | default y | 677 | default y |
diff --git a/networking/ntpd.c b/networking/ntpd.c index 44592ce54..adda6e5b0 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c | |||
@@ -42,6 +42,13 @@ | |||
42 | //usage: ) | 42 | //usage: ) |
43 | //usage: "\n -S PROG Run PROG after stepping time, stratum change, and every 11 mins" | 43 | //usage: "\n -S PROG Run PROG after stepping time, stratum change, and every 11 mins" |
44 | //usage: "\n -p PEER Obtain time from PEER (may be repeated)" | 44 | //usage: "\n -p PEER Obtain time from PEER (may be repeated)" |
45 | //usage: IF_FEATURE_NTPD_CONF( | ||
46 | //usage: "\n If -p is not given, read /etc/ntp.conf" | ||
47 | //usage: ) | ||
48 | |||
49 | // -l and -p options are not compatible with "standard" ntpd: | ||
50 | // it has them as "-l logfile" and "-p pidfile". | ||
51 | // -S and -w are not compat either, "standard" ntpd has no such opts. | ||
45 | 52 | ||
46 | #include "libbb.h" | 53 | #include "libbb.h" |
47 | #include <math.h> | 54 | #include <math.h> |
@@ -730,7 +737,7 @@ reset_peer_stats(peer_t *p, double offset) | |||
730 | } | 737 | } |
731 | 738 | ||
732 | static void | 739 | static void |
733 | add_peers(char *s) | 740 | add_peers(const char *s) |
734 | { | 741 | { |
735 | peer_t *p; | 742 | peer_t *p; |
736 | 743 | ||
@@ -2087,14 +2094,34 @@ static NOINLINE void ntp_init(char **argv) | |||
2087 | "d" /* compat */ | 2094 | "d" /* compat */ |
2088 | "46aAbgL", /* compat, ignored */ | 2095 | "46aAbgL", /* compat, ignored */ |
2089 | &peers, &G.script_name, &G.verbose); | 2096 | &peers, &G.script_name, &G.verbose); |
2090 | if (!(opts & (OPT_p|OPT_l))) | 2097 | |
2091 | bb_show_usage(); | ||
2092 | // if (opts & OPT_x) /* disable stepping, only slew is allowed */ | 2098 | // if (opts & OPT_x) /* disable stepping, only slew is allowed */ |
2093 | // G.time_was_stepped = 1; | 2099 | // G.time_was_stepped = 1; |
2094 | if (peers) { | 2100 | if (peers) { |
2095 | while (peers) | 2101 | while (peers) |
2096 | add_peers(llist_pop(&peers)); | 2102 | add_peers(llist_pop(&peers)); |
2097 | } else { | 2103 | } |
2104 | #if ENABLE_FEATURE_NTPD_CONF | ||
2105 | else { | ||
2106 | parser_t *parser; | ||
2107 | char *token[3]; | ||
2108 | |||
2109 | parser = config_open("/etc/ntp.conf"); | ||
2110 | while (config_read(parser, token, 3, 1, "# \t", PARSE_NORMAL)) { | ||
2111 | if (strcmp(token[0], "server") == 0 && token[1]) { | ||
2112 | add_peers(token[1]); | ||
2113 | continue; | ||
2114 | } | ||
2115 | bb_error_msg("skipping %s:%u: unimplemented command '%s'", | ||
2116 | "/etc/ntp.conf", parser->lineno, token[0] | ||
2117 | ); | ||
2118 | } | ||
2119 | config_close(parser); | ||
2120 | } | ||
2121 | #endif | ||
2122 | if (G.peer_cnt == 0) { | ||
2123 | if (!(opts & OPT_l)) | ||
2124 | bb_show_usage(); | ||
2098 | /* -l but no peers: "stratum 1 server" mode */ | 2125 | /* -l but no peers: "stratum 1 server" mode */ |
2099 | G.stratum = 1; | 2126 | G.stratum = 1; |
2100 | } | 2127 | } |