We should set system time to HW clock in early phase of the installation.
If we are not given info about it being UTC in kickstart, we have to guess
by searching for bootable partitions of other operating system(s).
Signed-off-by: Vratislav Podzimek <vpodzime(a)redhat.com>
---
anaconda | 11 ++++++++-
pyanaconda/kickstart.py | 7 ------
pyanaconda/timezone.py | 38 ++++++++++++++++++++++++++++++
pyanaconda/ui/gui/spokes/datetime_spoke.py | 20 ++++++++++++++++
4 files changed, 68 insertions(+), 8 deletions(-)
diff --git a/anaconda b/anaconda
index f291fb0..b121faf 100755
--- a/anaconda
+++ b/anaconda
@@ -972,14 +972,23 @@ if __name__ == "__main__":
from pyanaconda.storage import storageInitialize
from pyanaconda.packaging import payloadInitialize
from pyanaconda.network import networkInitialize
+ from pyanaconda.timezone import time_initialize, TIME_INIT_THREAD_NAME
if anaconda.rescue:
from pyanaconda.rescue import doRescue
doRescue(anaconda.rescue_mount, ksdata, anaconda.platform)
- threadMgr.add(AnacondaThread(name="AnaStorageThread",
target=storageInitialize, args=(anaconda.storage, ksdata, anaconda.protected)))
+ storage_thread_name = "AnaStorageThread"
+
+ threadMgr.add(AnacondaThread(name=storage_thread_name, target=storageInitialize,
args=(anaconda.storage, ksdata, anaconda.protected)))
threadMgr.add(AnacondaThread(name="AnaNetworkThread",
target=networkInitialize, args=(ksdata,)))
threadMgr.add(AnacondaThread(name="AnaPayloadThread",
target=payloadInitialize, args=(anaconda.storage, ksdata, anaconda.payload)))
+ threadMgr.add(AnacondaThread(name=TIME_INIT_THREAD_NAME,
+ target=time_initialize,
+ args=(anaconda.ksdata.timezone,
+ anaconda.storage,
+ storage_thread_name,
+ anaconda.bootloader)))
atexit.register(exitHandler, ksdata.reboot, anaconda.storage)
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
index 65a1e55..7ff6a13 100644
--- a/pyanaconda/kickstart.py
+++ b/pyanaconda/kickstart.py
@@ -1180,13 +1180,6 @@ class Services(commands.services.FC6_Services):
root=ROOT_PATH)
class Timezone(commands.timezone.F18_Timezone):
- def __init__(self, *args):
- commands.timezone.F18_Timezone.__init__(self, *args)
-
- #TODO: Do we need to set it to False in case of dual-boot?
- #default to UTC HW clock in Anaconda
- self.isUtc = True
-
def execute(self, *args):
# write out timezone configuration
if not timezone.is_valid_timezone(self.timezone):
diff --git a/pyanaconda/timezone.py b/pyanaconda/timezone.py
index 5337a21..1a8fab3 100644
--- a/pyanaconda/timezone.py
+++ b/pyanaconda/timezone.py
@@ -30,10 +30,13 @@ from collections import OrderedDict
from pyanaconda import localization
from pyanaconda import iutil
+from pyanaconda.threads import threadMgr
import logging
log = logging.getLogger("anaconda")
+TIME_INIT_THREAD_NAME = "AnaTimeThread"
+
# The following zones are not in pytz.common_timezones and
# Etc category in pytz.all_timezones includes some more,
# however confusing ones (like UCT, GMT+0, GMT-0,...)
@@ -47,6 +50,41 @@ class TimezoneConfigError(Exception):
"""Exception class for timezone configuration related
problems"""
pass
+def time_initialize(timezone, storage, storage_thread_name, bootloader):
+ """
+ Try to guess if RTC uses UTC time or not, set timezone.isUtc properly and
+ set system time from RTC using the UTC guess.
+ Guess is done by searching for bootable ntfs devices.
+
+ @param timezone: ksdata.timezone object
+ @param storage: storage.Storage instance
+ @param storage_thread_name: name of the thread running storageInitialize
+ @param bootloader: bootloader.Bootloader instance
+
+ """
+
+ if not timezone.isUtc:
+ # if set in the kickstart, nothing to do here
+
+ storage_init_thread = threadMgr.get(storage_thread_name)
+ if storage_init_thread is not None:
+ # wait until storage initialization is finished
+ storage_init_thread.join()
+
+ ntfs_devs = filter(lambda dev: dev.format.name == "ntfs",
+ storage.devices)
+
+ timezone.isUtc = not bootloader.has_windows(ntfs_devs)
+
+ cmd = "hwclock"
+ args = ["--hctosys"]
+ if timezone.isUtc:
+ args.append("--utc")
+ else:
+ args.append("--localtime")
+
+ iutil.execWithRedirect(cmd, args, stdout="/dev/tty5",
stderr="/dev/tty5")
+
def write_timezone_config(timezone, root):
"""
Write timezone configuration for the system specified by root.
diff --git a/pyanaconda/ui/gui/spokes/datetime_spoke.py
b/pyanaconda/ui/gui/spokes/datetime_spoke.py
index b9b59bb..3d7ed8e 100644
--- a/pyanaconda/ui/gui/spokes/datetime_spoke.py
+++ b/pyanaconda/ui/gui/spokes/datetime_spoke.py
@@ -39,6 +39,8 @@ from pyanaconda import iutil
from pyanaconda import network
from pyanaconda import ntp
from pyanaconda import flags
+from pyanaconda.ui.gui import communication
+from pyanaconda.timezone import TIME_INIT_THREAD_NAME
from pyanaconda.threads import threadMgr, AnacondaThread
import datetime
@@ -372,6 +374,24 @@ class DatetimeSpoke(NormalSpoke):
self._config_dialog = NTPconfigDialog(self.data)
self._config_dialog.initialize()
+ self._ready = False
+ threadMgr.add(AnacondaThread(name="AnaWaitTimeThread",
+ target=self.wait_for_time_init))
+
+ def wait_for_time_init(self):
+ time_init_thread = threadMgr.get(TIME_INIT_THREAD_NAME)
+ if time_init_thread is not None:
+ communication.send_message(self.__class__.__name__,
+ _("Restoring hardware time..."))
+ time_init_thread.join()
+
+ self._ready = True
+ communication.send_ready(self.__class__.__name__)
+
+ @property
+ def ready(self):
+ return self._ready
+
@property
def status(self):
if self.data.timezone.timezone:
--
1.7.11.7