#!/sbin/runscript # Copyright 1999-2003 Gentoo Technologies, Inc. # Distributed under the terms of the GNU General Public License v2 # $Header: /home/cvsroot/gentoo-src/rc-scripts/init.d/clock,v 1.14 2003/10/14 00:02:21 azarah Exp $ opts="${opts} save" depend() { need localmount } start() { local myopts="" local TBLURB="" local errstr="" if [ ! -f /etc/adjtime ] then echo "0.0 0 0.0" > /etc/adjtime fi if [ "${CLOCK}" = "UTC" ] then myopts="--utc" TBLURB="[UTC]" else myopts="--localtime" TBLURB="[Local Time]" fi if [ -n "$(grep 'UML' /proc/cpuinfo)" ] then ebegin "Setting system clock to hardware clock ${TBLURB}" eend 0 "Detected UML Environment; ignoring" return 0 elif [ -x /sbin/hwclock ] then ebegin "Setting system clock to hardware clock ${TBLURB}" errstr="$(/sbin/hwclock --adjust ${myopts} 2>&1 >/dev/null)" errstr="${errstr}$(/sbin/hwclock --hctosys ${myopts} 2>&1 >/dev/null)" #hwclock do not return a fail status if [ -n "${errstr}" ] then eend 1 "Failed to set system clock to hardware clock" return 1 else eend 0 return 0 fi else eend 1 "hwclock executable not found" fi } stop() { local myopts="" local TBLURB="" local errstr="" # Don't tweak hw clock on LiveCD halt [ -n "${CDBOOT}" ] && return 0 if [ "${CLOCK}" = "UTC" ] then myopts="--utc" TBLURB="[UTC]" else myopts="--localtime" TBLURB="[Local Time]" fi if [ -n "$(grep 'UML' /proc/cpuinfo)" ] then ebegin "Syncing hardware clock to system clock ${TBLURB}" eend 0 "Detected UML Environment; ignoring" return 0 elif [ -z "${SYNC_HW}" ] then ebegin "We don't want to sync hardware to system clock; skipping" eend 0 return 0 elif [ -x /sbin/hwclock ] then ebegin "Syncing hardware clock to system clock ${TBLURB}" errstr="$(/sbin/hwclock --systohc ${myopts} 2>&1 >/dev/null)" if [ -n "${errstr}" ] then eend 1 "Failed to set hardware clock to system clock" return 1 else eend 0 return 0 fi else eend 1 "hwclock executable not found" fi } save() { stop } # vim:ts=4