aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-01-25 19:30:16 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-01-25 19:30:16 +0100
commit24928ffd8d6eb7f410ea0a7b4530086cecfeea6e (patch)
treefa0c4b0cdcebb2c4a9f8d5aefcd42fcafcbb89da
parent3581c625151d25d8e1cbc80c44337d398d97cf42 (diff)
downloadbusybox-w32-24928ffd8d6eb7f410ea0a7b4530086cecfeea6e.tar.gz
busybox-w32-24928ffd8d6eb7f410ea0a7b4530086cecfeea6e.tar.bz2
busybox-w32-24928ffd8d6eb7f410ea0a7b4530086cecfeea6e.zip
ntpd: explain why scripts can be run in quick succession
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rwxr-xr-xexamples/var_service/ntpd/ntp.script20
-rw-r--r--networking/ntpd.c13
2 files changed, 24 insertions, 9 deletions
diff --git a/examples/var_service/ntpd/ntp.script b/examples/var_service/ntpd/ntp.script
index 90299ae8e..76c34bf74 100755
--- a/examples/var_service/ntpd/ntp.script
+++ b/examples/var_service/ntpd/ntp.script
@@ -1,10 +1,12 @@
1#!/bin/sh 1#!/bin/sh
2 2
3exec 2>/dev/null 3# Note that there is no provision to prevent several copies of the script
4echo "`tail -n 99 "$0.log"`" >"$0.log" 4# to be run in quick succession. In fact, it happens rather often
5 5# if initial syncronization results in a step.
6exec >>"$0.log" 6# You will see "step" and then "stratum" script runs, sometimes
7exec 2>&1 7# as close as only 0.002 seconds apart.
8#
9# Script should be ready to deal with this.
8 10
9dt=`date '+%Y-%m-%d %H:%M:%S'` 11dt=`date '+%Y-%m-%d %H:%M:%S'`
10 12
@@ -13,17 +15,23 @@ if test x"$stratum" != x"" \
13&& test 4 -ge "$stratum" \ 15&& test 4 -ge "$stratum" \
14&& test 128 -le "$poll_interval" \ 16&& test 128 -le "$poll_interval" \
15; then 17; then
18 echo "`tail -n 199 -- "$0.log" 2>/dev/null`" >"$0.log.$$"
16 echo "$dt: $1"\ 19 echo "$dt: $1"\
17 "freq_drift_ppm=$freq_drift_ppm"\ 20 "freq_drift_ppm=$freq_drift_ppm"\
18 "offset=$offset"\ 21 "offset=$offset"\
19 "stratum=$stratum"\ 22 "stratum=$stratum"\
20 "poll_interval=$poll_interval,"\ 23 "poll_interval=$poll_interval,"\
21 "setting hardware clock" 24 "setting hardware clock"\
25 >>"$0.log.$$"
26 mv -- "$0.log.$$" "$0.log"
22 exec hwclock --systohc 27 exec hwclock --systohc
23fi 28fi
24 29
30echo "`tail -n 199 -- "$0.log" 2>/dev/null`" >"$0.log.$$"
25echo "$dt: $1"\ 31echo "$dt: $1"\
26 "freq_drift_ppm=$freq_drift_ppm"\ 32 "freq_drift_ppm=$freq_drift_ppm"\
27 "offset=$offset"\ 33 "offset=$offset"\
28 "stratum=$stratum"\ 34 "stratum=$stratum"\
29 "poll_interval=$poll_interval"\ 35 "poll_interval=$poll_interval"\
36 >>"$0.log.$$"
37mv -- "$0.log.$$" "$0.log"
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 95dfdb119..04df3fa7f 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -735,6 +735,13 @@ send_query_to_peer(peer_t *p)
735} 735}
736 736
737 737
738/* Note that there is no provision to prevent several run_scripts
739 * to be done in quick succession. In fact, it happens rather often
740 * if initial syncronization results in a step.
741 * You will see "step" and then "stratum" script runs, sometimes
742 * as close as only 0.002 seconds apart.
743 * Script should be ready to deal with this.
744 */
738static void run_script(const char *action, double offset) 745static void run_script(const char *action, double offset)
739{ 746{
740 char *argv[3]; 747 char *argv[3];
@@ -1185,8 +1192,8 @@ update_local_clock(peer_t *p)
1185 abs_offset = fabs(offset); 1192 abs_offset = fabs(offset);
1186 1193
1187#if 0 1194#if 0
1188 /* If needed, -S script can detect this by looking at $offset 1195 /* If needed, -S script can do it by looking at $offset
1189 * env var and kill parent */ 1196 * env var and killing parent */
1190 /* If the offset is too large, give up and go home */ 1197 /* If the offset is too large, give up and go home */
1191 if (abs_offset > PANIC_THRESHOLD) { 1198 if (abs_offset > PANIC_THRESHOLD) {
1192 bb_error_msg_and_die("offset %f far too big, exiting", offset); 1199 bb_error_msg_and_die("offset %f far too big, exiting", offset);
@@ -2007,7 +2014,7 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv)
2007 nfds = poll(pfd, i, timeout * 1000); 2014 nfds = poll(pfd, i, timeout * 1000);
2008 gettime1900d(); /* sets G.cur_time */ 2015 gettime1900d(); /* sets G.cur_time */
2009 if (nfds <= 0) { 2016 if (nfds <= 0) {
2010 if (G.cur_time - G.last_script_run > 11*60) { 2017 if (G.script_name && G.cur_time - G.last_script_run > 11*60) {
2011 /* Useful for updating battery-backed RTC and such */ 2018 /* Useful for updating battery-backed RTC and such */
2012 run_script("periodic", G.last_update_offset); 2019 run_script("periodic", G.last_update_offset);
2013 gettime1900d(); /* sets G.cur_time */ 2020 gettime1900d(); /* sets G.cur_time */