aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2009-08-15 23:55:25 -0500
committerThomas Bächler <thomas@archlinux.org>2009-08-22 11:25:27 +0200
commit2008846efe204b79d1c0f281d609a1f4b23431c8 (patch)
tree4b9404966d4593af87e609d9ad5b66129a16c9e5
parentd1f86dbf7819a782df812dde8282a03ab1f82faf (diff)
downloadinitscripts-2008846efe204b79d1c0f281d609a1f4b23431c8.tar.xz
Allow skipping of all hardware clock adjustments
For virtualized machines, the hardware clock doesn't actually exist, so all hwclock calls fail and print error messages during system startup, shutdown, and the hourly adjtime cronjob. By explicitly looking for HARDWARECLOCK to be set to 'UTC' or 'localtime', all other values will result in hwclock calls being skipped (e.g. set the variable to 'none'). Signed-off-by: Dan McGee <dan@archlinux.org>
-rwxr-xr-xadjtime.cron18
-rw-r--r--rc.conf3
-rwxr-xr-xrc.shutdown2
-rwxr-xr-xrc.sysinit15
4 files changed, 29 insertions, 9 deletions
diff --git a/adjtime.cron b/adjtime.cron
index 40c02f2..b1c8950 100755
--- a/adjtime.cron
+++ b/adjtime.cron
@@ -1,3 +1,17 @@
-#!/bin/sh
+#!/bin/bash
# Update our hwclock for system drift
-/sbin/hwclock --adjust
+
+. /etc/rc.conf
+
+HWCLOCK_PARAMS="--adjust"
+if [ "$HARDWARECLOCK" = "UTC" ]; then
+ HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc"
+elif [ "$HARDWARECLOCK" = "localtime" ]; then
+ HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime"
+else
+ HWCLOCK_PARAMS=""
+fi
+
+if [ -n "$HWCLOCK_PARAMS" ]; then
+ /sbin/hwclock $HWCLOCK_PARAMS
+fi
diff --git a/rc.conf b/rc.conf
index b9495f8..252a9b1 100644
--- a/rc.conf
+++ b/rc.conf
@@ -7,7 +7,8 @@
# -----------------------------------------------------------------------
#
# LOCALE: available languages can be listed with the 'locale -a' command
-# HARDWARECLOCK: set to "UTC" or "localtime"
+# HARDWARECLOCK: set to "UTC" or "localtime", any other value will result
+# in the hardware clock being left untouched (useful for virtualization)
# TIMEZONE: timezones are found in /usr/share/zoneinfo
# KEYMAP: keymaps are found in /usr/share/kbd/keymaps
# CONSOLEFONT: found in /usr/share/kbd/consolefonts (only needed for non-US)
diff --git a/rc.shutdown b/rc.shutdown
index b0d8195..e2a4a84 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -80,7 +80,7 @@ elif [ "$HARDWARECLOCK" = "localtime" ]; then
else
HWCLOCK_PARAMS=""
fi
-if [ "$HWCLOCK_PARAMS" != "" ]; then
+if [ -n "$HWCLOCK_PARAMS" ]; then
/sbin/hwclock $HWCLOCK_PARAMS
fi
stat_done
diff --git a/rc.sysinit b/rc.sysinit
index 322b512..0e67721 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -35,7 +35,8 @@ fi
# enable rtc access
/sbin/modprobe rtc-cmos >/dev/null 2>&1
-RTC_MAJOR=$(/bin/grep -w rtc /proc/devices 2>/dev/null); RTC_MAJOR="${RTC_MAJOR%% *}"
+RTC_MAJOR=$(/bin/grep -w rtc /proc/devices 2>/dev/null)
+RTC_MAJOR="${RTC_MAJOR%% *}"
if [ -n "$RTC_MAJOR" ]; then
/bin/mknod /dev/rtc0 c $RTC_MAJOR 0
/bin/ln -s /dev/rtc0 /dev/rtc
@@ -44,13 +45,15 @@ fi
HWCLOCK_PARAMS="--hctosys"
if [ "$HARDWARECLOCK" = "UTC" ]; then
HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc"
-else
+elif [ "$HARDWARECLOCK" = "localtime" ]; then
HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime"
+else
+ HWCLOCK_PARAMS=""
fi
# Set clock early to fix some bugs with filesystem checks
# Clock is set again later to match rc.conf
-if [ -f /etc/localtime ]; then
+if [ -n "$HWCLOCK_PARAMS" -a -f /etc/localtime ]; then
/sbin/hwclock $HWCLOCK_PARAMS --noadjfile
fi
@@ -302,8 +305,10 @@ if [ "$TIMEZONE" != "" -a -e "/usr/share/zoneinfo/$TIMEZONE" ]; then
/bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
fi
-/sbin/hwclock --adjust #Adjust for system drift
-/sbin/hwclock $HWCLOCK_PARAMS
+if [ -n "$HWCLOCK_PARAMS" ]; then
+ /sbin/hwclock --adjust #Adjust for system drift
+ /sbin/hwclock $HWCLOCK_PARAMS
+fi
stat_done
RANDOM_SEED=/var/lib/misc/random-seed