From ff53993433666c05902d50945d1521a705cc4ea2 Mon Sep 17 00:00:00 2001 From: cy Date: Thu, 19 Oct 2017 03:17:50 +0000 Subject: [PATCH] Anticongestion refinements for ntpd rc script. This reverts r324681 and checks if ntp leapfile needs fetching before entering into the anticongestion sleep. Unfortunately some ports still use their own sleeps so, this commit doesn't address the complete problem which is compounded by every port that uses its own anticongestion mechanism. Discussed with: asomers --- etc/defaults/periodic.conf | 2 -- etc/periodic/daily/480.leapfile-ntpd | 9 ++------- etc/rc.d/ntpd | 20 ++++++++++++++++++-- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/etc/defaults/periodic.conf b/etc/defaults/periodic.conf index 64d9ba487e10..801733301318 100644 --- a/etc/defaults/periodic.conf +++ b/etc/defaults/periodic.conf @@ -141,8 +141,6 @@ daily_status_mail_rejects_shorten="NO" # Shorten output # 480.leapfile-ntpd daily_ntpd_leapfile_enable="YES" # Fetch NTP leapfile -daily_ntpd_leapfile_background="NO" # Fetch NTP leapfile - # in the background # 480.status-ntpd daily_status_ntpd_enable="NO" # Check NTP status diff --git a/etc/periodic/daily/480.leapfile-ntpd b/etc/periodic/daily/480.leapfile-ntpd index 0924a7445cad..a693986e0dd1 100755 --- a/etc/periodic/daily/480.leapfile-ntpd +++ b/etc/periodic/daily/480.leapfile-ntpd @@ -13,15 +13,10 @@ fi case "$daily_ntpd_leapfile_enable" in [Yy][Ee][Ss]) - case "$daily_ntpd_leapfile_background" in - [Yy][Ee][Ss]) - (anticongestion && service ntpd onefetch) & - ;; - *) + if service ntpd oneneedfetch; then anticongestion service ntpd onefetch - ;; - esac + fi ;; esac diff --git a/etc/rc.d/ntpd b/etc/rc.d/ntpd index a0cb54362541..6021f89b0c2d 100755 --- a/etc/rc.d/ntpd +++ b/etc/rc.d/ntpd @@ -15,8 +15,9 @@ desc="Network Time Protocol daemon" rcvar="ntpd_enable" command="/usr/sbin/${name}" pidfile="/var/run/${name}.pid" -extra_commands="fetch" +extra_commands="fetch needfetch" fetch_cmd="ntpd_fetch_leapfile" +needfetch_cmd="ntpd_needfetch_leapfile" start_precmd="ntpd_precmd" load_rc_config $name @@ -90,7 +91,7 @@ ntpd_init_leapfile() { fi } -ntpd_fetch_leapfile() { +ntpd_needfetch_leapfile() { local ntp_tmp_leapfile rc verbose if checkyesno ntp_leapfile_fetch_verbose; then @@ -122,6 +123,21 @@ ntpd_fetch_leapfile() { ntp_leap_fetch_date=$((ntp_leap_expiry-ntp_leapfile_expiry_seconds)) if [ $(current_ntp_ts) -ge $ntp_leap_fetch_date ]; then $verbose Within ntp leapfile expiry limit, initiating fetch + # Return code 0: ntp leapfile fetch needed + return 0 + fi + # Return code 1: ntp leapfile fetch not needed + return 1 +} + +ntpd_fetch_leapfile() { + if checkyesno ntp_leapfile_fetch_verbose; then + verbose=echo + else + verbose=: + fi + + if ntpd_needfetch_leapfile ; then for url in $ntp_leapfile_sources ; do $verbose fetching $url fetch $ntp_leapfile_fetch_opts -o $ntp_tmp_leapfile $url && break -- 2.41.0