diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-06 12:27:47 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-06 12:27:47 +0100 |
commit | ede737b7cfb2d86965ebde07004ede3d8c3f1ab8 (patch) | |
tree | 1d84c6e20dada0e412a1aabbd5133a6cf960c347 /networking/ntpd.c | |
parent | 79ae534ac7a1e1ead80737b4b09769916c2bbb49 (diff) | |
download | busybox-w32-ede737b7cfb2d86965ebde07004ede3d8c3f1ab8.tar.gz busybox-w32-ede737b7cfb2d86965ebde07004ede3d8c3f1ab8.tar.bz2 busybox-w32-ede737b7cfb2d86965ebde07004ede3d8c3f1ab8.zip |
ntpd: add -S PROG option. This feature is crucial for CMOS/RTC syncronization
function old new delta
run_script 112 278 +166
ntpd_main 779 825 +46
update_local_clock 824 858 +34
packed_usage 26518 26540 +22
ntp_init 366 371 +5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/0 up/down: 273/0) Total: 273 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/ntpd.c')
-rw-r--r-- | networking/ntpd.c | 61 |
1 files changed, 55 insertions, 6 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c index ab1c58c97..81474547e 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c | |||
@@ -194,7 +194,8 @@ enum { | |||
194 | /* Non-compat options: */ | 194 | /* Non-compat options: */ |
195 | OPT_w = (1 << 4), | 195 | OPT_w = (1 << 4), |
196 | OPT_p = (1 << 5), | 196 | OPT_p = (1 << 5), |
197 | OPT_l = (1 << 6) * ENABLE_FEATURE_NTPD_SERVER, | 197 | OPT_S = (1 << 6), |
198 | OPT_l = (1 << 7) * ENABLE_FEATURE_NTPD_SERVER, | ||
198 | }; | 199 | }; |
199 | 200 | ||
200 | struct globals { | 201 | struct globals { |
@@ -205,6 +206,9 @@ struct globals { | |||
205 | double reftime; | 206 | double reftime; |
206 | /* total dispersion to currently selected reference clock */ | 207 | /* total dispersion to currently selected reference clock */ |
207 | double rootdisp; | 208 | double rootdisp; |
209 | |||
210 | double last_script_run; | ||
211 | char *script_name; | ||
208 | llist_t *ntp_peers; | 212 | llist_t *ntp_peers; |
209 | #if ENABLE_FEATURE_NTPD_SERVER | 213 | #if ENABLE_FEATURE_NTPD_SERVER |
210 | int listen_fd; | 214 | int listen_fd; |
@@ -682,6 +686,38 @@ send_query_to_peer(peer_t *p) | |||
682 | } | 686 | } |
683 | 687 | ||
684 | 688 | ||
689 | static void run_script(const char *action) | ||
690 | { | ||
691 | char *argv[3]; | ||
692 | char *env1, *env2; | ||
693 | |||
694 | if (!G.script_name) | ||
695 | return; | ||
696 | |||
697 | argv[0] = (char*) G.script_name; | ||
698 | argv[1] = (char*) action; | ||
699 | argv[2] = NULL; | ||
700 | |||
701 | VERB1 bb_error_msg("executing '%s %s'", G.script_name, action); | ||
702 | |||
703 | env1 = xasprintf("stratum=%u", G.stratum); | ||
704 | putenv(env1); | ||
705 | env2 = xasprintf("freq_drift_ppm=%ld", G.kernel_freq_drift); | ||
706 | putenv(env2); | ||
707 | /* Other items of potential interest: selected peer, | ||
708 | * rootdelay, reftime, rootdisp, refid, ntp_status, poll_exp, | ||
709 | * last_update_offset, last_update_recv_time, discipline_jitter | ||
710 | */ | ||
711 | |||
712 | wait4pid(spawn(argv)); | ||
713 | G.last_script_run = G.cur_time; | ||
714 | |||
715 | unsetenv("stratum"); | ||
716 | unsetenv("freq_drift_ppm"); | ||
717 | free(env1); | ||
718 | free(env2); | ||
719 | } | ||
720 | |||
685 | static NOINLINE void | 721 | static NOINLINE void |
686 | step_time(double offset) | 722 | step_time(double offset) |
687 | { | 723 | { |
@@ -1140,6 +1176,9 @@ update_local_clock(peer_t *p) | |||
1140 | G.polladj_count = 0; | 1176 | G.polladj_count = 0; |
1141 | G.poll_exp = MINPOLL; | 1177 | G.poll_exp = MINPOLL; |
1142 | G.stratum = MAXSTRAT; | 1178 | G.stratum = MAXSTRAT; |
1179 | |||
1180 | run_script("step"); | ||
1181 | |||
1143 | if (G.discipline_state == STATE_NSET) { | 1182 | if (G.discipline_state == STATE_NSET) { |
1144 | set_new_values(STATE_FREQ, /*offset:*/ 0, recv_time); | 1183 | set_new_values(STATE_FREQ, /*offset:*/ 0, recv_time); |
1145 | return 1; /* "ok to increase poll interval" */ | 1184 | return 1; /* "ok to increase poll interval" */ |
@@ -1225,7 +1264,10 @@ update_local_clock(peer_t *p) | |||
1225 | set_new_values(STATE_SYNC, offset, recv_time); | 1264 | set_new_values(STATE_SYNC, offset, recv_time); |
1226 | break; | 1265 | break; |
1227 | } | 1266 | } |
1228 | G.stratum = p->lastpkt_stratum + 1; | 1267 | if (G.stratum != p->lastpkt_stratum + 1) { |
1268 | G.stratum = p->lastpkt_stratum + 1; | ||
1269 | run_script("stratum"); | ||
1270 | } | ||
1229 | } | 1271 | } |
1230 | 1272 | ||
1231 | G.reftime = G.cur_time; | 1273 | G.reftime = G.cur_time; |
@@ -1729,17 +1771,17 @@ static NOINLINE void ntp_init(char **argv) | |||
1729 | G.stratum = MAXSTRAT; | 1771 | G.stratum = MAXSTRAT; |
1730 | if (BURSTPOLL != 0) | 1772 | if (BURSTPOLL != 0) |
1731 | G.poll_exp = BURSTPOLL; /* speeds up initial sync */ | 1773 | G.poll_exp = BURSTPOLL; /* speeds up initial sync */ |
1732 | G.reftime = G.last_update_recv_time = gettime1900d(); /* sets G.cur_time too */ | 1774 | G.last_script_run = G.reftime = G.last_update_recv_time = gettime1900d(); /* sets G.cur_time too */ |
1733 | 1775 | ||
1734 | /* Parse options */ | 1776 | /* Parse options */ |
1735 | peers = NULL; | 1777 | peers = NULL; |
1736 | opt_complementary = "dd:p::wn"; /* d: counter; p: list; -w implies -n */ | 1778 | opt_complementary = "dd:p::wn"; /* d: counter; p: list; -w implies -n */ |
1737 | opts = getopt32(argv, | 1779 | opts = getopt32(argv, |
1738 | "nqNx" /* compat */ | 1780 | "nqNx" /* compat */ |
1739 | "wp:"IF_FEATURE_NTPD_SERVER("l") /* NOT compat */ | 1781 | "wp:S:"IF_FEATURE_NTPD_SERVER("l") /* NOT compat */ |
1740 | "d" /* compat */ | 1782 | "d" /* compat */ |
1741 | "46aAbgL", /* compat, ignored */ | 1783 | "46aAbgL", /* compat, ignored */ |
1742 | &peers, &G.verbose); | 1784 | &peers, &G.script_name, &G.verbose); |
1743 | if (!(opts & (OPT_p|OPT_l))) | 1785 | if (!(opts & (OPT_p|OPT_l))) |
1744 | bb_show_usage(); | 1786 | bb_show_usage(); |
1745 | // if (opts & OPT_x) /* disable stepping, only slew is allowed */ | 1787 | // if (opts & OPT_x) /* disable stepping, only slew is allowed */ |
@@ -1854,8 +1896,15 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) | |||
1854 | VERB2 bb_error_msg("poll %us, sockets:%u", timeout, i); | 1896 | VERB2 bb_error_msg("poll %us, sockets:%u", timeout, i); |
1855 | nfds = poll(pfd, i, timeout * 1000); | 1897 | nfds = poll(pfd, i, timeout * 1000); |
1856 | gettime1900d(); /* sets G.cur_time */ | 1898 | gettime1900d(); /* sets G.cur_time */ |
1857 | if (nfds <= 0) | 1899 | if (nfds <= 0) { |
1900 | if (G.adjtimex_was_done | ||
1901 | && G.cur_time - G.last_script_run > 11*60 | ||
1902 | ) { | ||
1903 | /* Useful for updating battery-backed RTC and such */ | ||
1904 | run_script("periodic"); | ||
1905 | } | ||
1858 | continue; | 1906 | continue; |
1907 | } | ||
1859 | 1908 | ||
1860 | /* Process any received packets */ | 1909 | /* Process any received packets */ |
1861 | j = 0; | 1910 | j = 0; |