--- b/etc/defaults/rc.conf Wed Mar 27 15:06:58 2019 +0100 +++ b/etc/defaults/rc.conf Tue Apr 02 12:48:57 2019 +0200 @@ -363,9 +363,11 @@ timed_enable="NO" # Run the time daemon (or NO). timed_flags="" # Flags to timed (if enabled). ntpdate_enable="NO" # Run ntpdate to sync time on boot (or NO). +ntpdate_resume_enable="NO" # Run ntpdate to sync time on resume (or NO). ntpdate_program="/usr/sbin/ntpdate" # path to ntpdate, if you want a different one. -ntpdate_flags="-b" # Flags to ntpdate (if enabled). -ntpdate_config="/etc/ntp.conf" # ntpdate(8) configuration file +ntpdate_flags="-b" # Flags to ntpdate used on boot (if enabled). +ntpdate_resume_flags="-bu" # Flags to ntpdate used on resume (if enabled). +ntpdate_config="/etc/ntp.conf" # ntpd(8) configuration file ntpdate_hosts="" # Whitespace-separated list of ntpdate(8) servers. ntpd_enable="NO" # Run ntpd Network Time Protocol (or NO). ntpd_program="/usr/sbin/ntpd" # path to ntpd, if you want a different one. --- b/etc/rc.d/ntpdate Wed Mar 27 15:06:58 2019 +0100 +++ b/etc/rc.d/ntpdate Tue Apr 02 12:48:57 2019 +0200 @@ -5,18 +5,43 @@ # PROVIDE: ntpdate # REQUIRE: NETWORKING syslogd -# KEYWORD: nojail +# KEYWORD: nojail resume . /etc/rc.subr name="ntpdate" desc="Set the date and time via NTP" rcvar="ntpdate_enable" -stop_cmd=":" -start_cmd="ntpdate_start" +rcvars="ntpdate_resume_enable ntpdate_program ntpdate_flags \ +ntpdate_resume_flags ntpdate_hosts ntpdate_config" + +ntpdate_enable_defval="NO" +ntpdate_resume_enable_defval="NO" +ntpdate_program_defval="/usr/sbin/ntpdate" +ntpdate_flags_defval="-b" +ntpdate_resume_flags_defval="-bu" +ntpdate_hosts_defval="" +ntpdate_config_defval="/etc/ntp.conf" -ntpdate_start() +ntpdate_enable_desc="Run ntpdate to sync time on boot." +ntpdate_resume_enable_desc="Run ntpdate to sync time on resume \ +(if enabled at boot)." +ntpdate_program_desc="Path to ntpdate, if you want a different one." +ntpdate_flags_desc="Flags to ntpdate used on boot (if enabled)." +ntpdate_resume_flags_desc="Flags to ntpdate used on resume (if enabled)." +ntpdate_hosts_desc="Whitespace-separated list of ntp(8) servers." +ntpdate_config_desc="ntpd(8) configuration file" + +extra_commands="resume" +start_cmd="ntpdate_start" +resume_cmd="ntpdate_resume" +stop_cmd=":" + +do_ntpdate() { + local options + options=$1 + if [ -z "$ntpdate_hosts" -a -f "$ntpdate_config" ]; then ntpdate_hosts=`awk ' /^server[ \t]*127.127/ {next} @@ -27,7 +52,20 @@ fi if [ -n "$ntpdate_hosts" -o -n "$rc_flags" ]; then echo "Setting date via ntp." - ${ntpdate_program:-ntpdate} $rc_flags $ntpdate_hosts + ${ntpdate_program:-ntpdate} $options $ntpdate_hosts + fi +} + +ntpdate_start() +{ + do_ntpdate $rc_flags +} + +ntpdate_resume() +{ + # We use an unprivileged port on resume because ntpd may be running. + if checkyesno ntpdate_resume_enable ; then + do_ntpdate $ntpdate_resume_flags fi }