19330Slana#!/bin/sh
25840Skshefov#
35840Skshefov# $FreeBSD$
45840Skshefov#
55840Skshefov
68729Sserb# PROVIDE: ntpd
75840Skshefov# REQUIRE: DAEMON ntpdate FILESYSTEMS devfs
85840Skshefov# BEFORE:  LOGIN
95840Skshefov# KEYWORD: nojail shutdown
105840Skshefov
115840Skshefov. /etc/rc.subr
125840Skshefov
135840Skshefovname="ntpd"
145840Skshefovrcvar="ntpd_enable"
155840Skshefovcommand="/usr/sbin/${name}"
165840Skshefovpidfile="/var/run/${name}.pid"
175840Skshefovstart_precmd="ntpd_precmd"
185840Skshefov
195840Skshefovload_rc_config $name
205840Skshefov
215840Skshefovntpd_precmd()
225840Skshefov{
235840Skshefov	rc_flags="-c ${ntpd_config} ${ntpd_flags}"
245840Skshefov
255840Skshefov	if checkyesno ntpd_sync_on_start; then
265840Skshefov		rc_flags="-g $rc_flags"
275840Skshefov	fi
285840Skshefov
295840Skshefov	if [ -z "$ntpd_chrootdir" ]; then
305840Skshefov		return 0;
315840Skshefov	fi
325840Skshefov
335840Skshefov	# If running in a chroot cage, ensure that the appropriate files
345840Skshefov	# exist inside the cage, as well as helper symlinks into the cage
355840Skshefov	# from outside.
365840Skshefov	#
375840Skshefov	# As this is called after the is_running and required_dir checks
385840Skshefov	# are made in run_rc_command(), we can safely assume ${ntpd_chrootdir}
395840Skshefov	# exists and ntpd isn't running at this point (unless forcestart
405840Skshefov	# is used).
415840Skshefov	#
425840Skshefov	if [ ! -c "${ntpd_chrootdir}/dev/clockctl" ]; then
435840Skshefov		rm -f "${ntpd_chrootdir}/dev/clockctl"
445840Skshefov		( cd /dev ; /bin/pax -rw -pe clockctl "${ntpd_chrootdir}/dev" )
455840Skshefov	fi
465840Skshefov	ln -fs "${ntpd_chrootdir}/var/db/ntp.drift" /var/db/ntp.drift
475840Skshefov
48	#	Change run_rc_commands()'s internal copy of $ntpd_flags
49	#
50	rc_flags="-u ntpd:ntpd -i ${ntpd_chrootdir} $rc_flags"
51}
52
53run_rc_command "$1"
54