/[baselayout]/trunk/init.d.Linux/clock
Gentoo

Contents of /trunk/init.d.Linux/clock

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2763 - (show annotations) (download)
Tue Jul 10 19:09:41 2007 UTC (7 years ago) by uberlord
File size: 3184 byte(s)
init scripts and their extra options can now have descriptions, #184327.
1 #!/sbin/runscript
2 # Copyright 1999-2007 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 opts="save"
6
7 description="Sets the local clock to UTC or Local Time."
8 description_save="Saves the current time in the BIOS."
9
10 depend() {
11 case "${CLOCK_ADJTIME}" in
12 "") before *;;
13 /etc/*) need checkroot;;
14 *) need localmount;;
15 esac
16 }
17
18 setupopts() {
19 case "${RC_SYS}" in
20 UML|VPS|XEN)
21 TBLURB="${RC_SYS}"
22 fakeit=1
23 ;;
24 *)
25 case "$(uname -m)" in
26 s390*)
27 TBLURB="s390"
28 fakeit=1
29 ;;
30 *)
31 if [ -e /proc/devices ] && grep -q " cobd$" /proc/devices ; then
32 TBLURB="coLinux"
33 fakeit=1
34 elif [ "${CLOCK}" = "UTC" ] ; then
35 myopts="--utc"
36 TBLURB="UTC"
37 else
38 myopts="--localtime"
39 TBLURB="Local Time"
40 fi
41 ;;
42 esac
43 ;;
44 esac
45 [ ${fakeit} -eq 1 ] && return 0
46
47 if [ -z "${CLOCK_ADJTIME}" -o ! -w /etc ] ; then
48 myadj="--noadjfile"
49 else
50 myadj="--adjust"
51 fi
52
53 [ "${SRM}" = "yes" ] && myopts="${myopts} --srm"
54 [ "${ARC}" = "arc" ] && myopts="${myopts} --arc"
55 myopts="${myopts} ${CLOCK_OPTS}"
56
57 # Make sure user isn't using rc.conf anymore.
58 if grep -q "^CLOCK=" /etc/rc.conf ; then
59 ewarn $"CLOCK should not be set in /etc/rc.conf but in /etc/conf.d/clock"
60 fi
61
62 # Make sure people set their timezone ... we do it here
63 # even though we don't actually use the variable so that
64 # people see the warning on boot.
65 if [ -z "${CDBOOT}" -a "${TIMEZONE-Factory}" = "Factory" ] ; then
66 ewarn "Your TIMEZONE in /etc/conf.d/clock is still set to Factory!"
67 fi
68 }
69
70 start() {
71 local myopts= myadj= TBLURB= fakeit=0 errstr="" retval=0
72
73 if [ -x /sbin/hwclock ] ; then
74 [ -w "${CLOCK_ADJTIME}" ] && echo "0.0 0 0.0" > "${CLOCK_ADJTIME}"
75 fi
76
77 setupopts
78
79 if [ ${fakeit} -ne 1 -a -e /proc/modules -a ! -e /dev/rtc ] ; then
80 modprobe -q rtc || modprobe -q genrtc
81 fi
82
83 ebegin "Setting system clock using the hardware clock" "[${TBLURB}]"
84 if [ ${fakeit} -eq 1 ] ; then
85 retval=0
86 elif [ -x /sbin/hwclock ] ; then
87 # Don't call hwclock unless we need to
88 if [ "${TBLURB}" != "UTC" -o "${myadj}" != "--noadjfile" ] ; then
89 # Since hwclock always exit's with a 0, need to check its output.
90 errstr="$(/sbin/hwclock ${myadj} ${myopts} 2>&1 >/dev/null)"
91 errstr="${errstr}$(/sbin/hwclock --hctosys ${myopts} 2>&1 >/dev/null)"
92
93 if [ -n "${errstr}" ] ; then
94 ewarn "${errstr}"
95 retval=1
96 fi
97 errstr="Failed to set clock"
98 fi
99 else
100 retval=1
101 errstr="/sbin/hwclock not found"
102 fi
103 eend ${retval} "${errstr}" "You will need to set the clock yourself"
104
105 return 0
106 }
107
108 stop() {
109 # Don't tweak the hardware clock on LiveCD halt.
110 [ -n "${CDBOOT}" -o "${CLOCK_SYSTOHC}" != "yes" ] && return 0
111
112 local myopts= myadj= TBLURB= fakeit=0 errstr="" retval=0
113
114 setupopts
115
116 ebegin "Setting hardware clock using the system clock" "[${TBLURB}]"
117 if [ ${fakeit} -eq 1 ] ; then
118 retval=0
119 elif [ -x /sbin/hwclock ] ; then
120 [ -z "$(/sbin/hwclock --systohc ${myopts} 2>&1 >/dev/null)" ]
121 retval=$?
122 errstr="Failed to sync clocks"
123 else
124 retval=1
125 errstr="/sbin/hwclock not found"
126 fi
127 eend ${retval} "${errstr}"
128 }
129
130 save() {
131 CLOCK_SYSTOHC="yes"
132 stop
133 }
134
135 # vim: set ts=4 :

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20