From a2119d62c0dea95e138bb3c962e2735a681924bc Mon Sep 17 00:00:00 2001 From: Ian Lepore Date: Thu, 23 May 2019 01:41:49 +0000 Subject: [PATCH] Handle the driftfile option correctly when ntpd_flags is empty. The logic I originally wrote to detect whether a driftfile option was in the set of flags was based on the result of removing the pattern *flag* being an empty string. That didn't handle the case where the string was empty to begin with. Doh! So now it also specifically checks for an empty string. The result of the bad check was that ntpd would run without a driftfile, but it would do so only if it was running as root instead of the non-priveleged ntpd user, which isn't a typical case. Ntpd runs fine without a driftfile, although it does take it longer to stabilize the clock frequency at startup. Reported by: avg@ Pointy hat: ian@ MFC after: some testing --- libexec/rc/rc.d/ntpd | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libexec/rc/rc.d/ntpd b/libexec/rc/rc.d/ntpd index 553575215593..7a4ffa44b1f4 100755 --- a/libexec/rc/rc.d/ntpd +++ b/libexec/rc/rc.d/ntpd @@ -87,12 +87,14 @@ ntpd_precmd() # Otherwise, figure out what to do about the driftfile option. If set # by the admin, we don't add the option. If the file exists in the old # default location we use that, else we use the new default location. + if can_run_nonroot; then _user="ntpd" driftopt="-f ${_ntp_default_driftfile}" - elif [ -z "${rc_flags##*-f*}" ] || - [ -z "${rc_flags##*--driftfile*}" ] || - grep -q "^[ \t]*driftfile" "${ntpd_config}"; then + elif grep -q "^[ \t]*driftfile" "${ntpd_config}" || + [ -n "${rc_flags}" ] && + ( [ -z "${rc_flags##*-f*}" ] || + [ -z "${rc_flags##*--driftfile*}" ] ); then driftopt="" # admin set the option, we don't need to add it. elif [ -f "${_ntp_old_driftfile}" ]; then driftopt="-f ${_ntp_old_driftfile}"