summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2010-01-25 19:30:16 +0100
committerDenys Vlasenko2010-01-25 19:30:16 +0100
commit24928ffd8d6eb7f410ea0a7b4530086cecfeea6e (patch)
treefa0c4b0cdcebb2c4a9f8d5aefcd42fcafcbb89da
parent3581c625151d25d8e1cbc80c44337d398d97cf42 (diff)
downloadbusybox-24928ffd8d6eb7f410ea0a7b4530086cecfeea6e.zip
busybox-24928ffd8d6eb7f410ea0a7b4530086cecfeea6e.tar.gz
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 90299ae..76c34bf 100755
--- a/examples/var_service/ntpd/ntp.script
+++ b/examples/var_service/ntpd/ntp.script
@@ -1,10 +1,12 @@
#!/bin/sh
-exec 2>/dev/null
-echo "`tail -n 99 "$0.log"`" >"$0.log"
-
-exec >>"$0.log"
-exec 2>&1
+# Note that there is no provision to prevent several copies of the script
+# to be run in quick succession. In fact, it happens rather often
+# if initial syncronization results in a step.
+# You will see "step" and then "stratum" script runs, sometimes
+# as close as only 0.002 seconds apart.
+#
+# Script should be ready to deal with this.
dt=`date '+%Y-%m-%d %H:%M:%S'`
@@ -13,17 +15,23 @@ if test x"$stratum" != x"" \
&& test 4 -ge "$stratum" \
&& test 128 -le "$poll_interval" \
; then
+ echo "`tail -n 199 -- "$0.log" 2>/dev/null`" >"$0.log.$$"
echo "$dt: $1"\
"freq_drift_ppm=$freq_drift_ppm"\
"offset=$offset"\
"stratum=$stratum"\
"poll_interval=$poll_interval,"\
- "setting hardware clock"
+ "setting hardware clock"\
+ >>"$0.log.$$"
+ mv -- "$0.log.$$" "$0.log"
exec hwclock --systohc
fi
+echo "`tail -n 199 -- "$0.log" 2>/dev/null`" >"$0.log.$$"
echo "$dt: $1"\
"freq_drift_ppm=$freq_drift_ppm"\
"offset=$offset"\
"stratum=$stratum"\
"poll_interval=$poll_interval"\
+ >>"$0.log.$$"
+mv -- "$0.log.$$" "$0.log"
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 95dfdb1..04df3fa 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -735,6 +735,13 @@ send_query_to_peer(peer_t *p)
}
+/* Note that there is no provision to prevent several run_scripts
+ * to be done in quick succession. In fact, it happens rather often
+ * if initial syncronization results in a step.
+ * You will see "step" and then "stratum" script runs, sometimes
+ * as close as only 0.002 seconds apart.
+ * Script should be ready to deal with this.
+ */
static void run_script(const char *action, double offset)
{
char *argv[3];
@@ -1185,8 +1192,8 @@ update_local_clock(peer_t *p)
abs_offset = fabs(offset);
#if 0
- /* If needed, -S script can detect this by looking at $offset
- * env var and kill parent */
+ /* If needed, -S script can do it by looking at $offset
+ * env var and killing parent */
/* If the offset is too large, give up and go home */
if (abs_offset > PANIC_THRESHOLD) {
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)
nfds = poll(pfd, i, timeout * 1000);
gettime1900d(); /* sets G.cur_time */
if (nfds <= 0) {
- if (G.cur_time - G.last_script_run > 11*60) {
+ if (G.script_name && G.cur_time - G.last_script_run > 11*60) {
/* Useful for updating battery-backed RTC and such */
run_script("periodic", G.last_update_offset);
gettime1900d(); /* sets G.cur_time */