From 2897a795c4f9982475095d9817dd81e4a9be0970 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Wed, 18 Jan 2012 16:59:58 +0100 Subject: [PATCH] dom0/vm: set VM timezone same as in dom0 - on VM boot (#413) --- dom0/qvm-core/qubes.py | 19 +++++++++++++++++++ vm-init.d/qubes_core | 7 +++++++ vm-systemd/qubes-sysinit.sh | 6 ++++++ 3 files changed, 32 insertions(+) diff --git a/dom0/qvm-core/qubes.py b/dom0/qvm-core/qubes.py index dfd34d84..42b781f4 100755 --- a/dom0/qvm-core/qubes.py +++ b/dom0/qvm-core/qubes.py @@ -644,6 +644,19 @@ class QubesVm(object): f_private.truncate (size) f_private.close () + # FIXME: should be outside of QubesVM? + def get_timezone(self): + clock_config = open('/etc/sysconfig/clock', "r") + clock_config_lines = clock_config.readlines() + clock_config.close() + zone_re = re.compile(r'^ZONE="(.*)"') + for line in clock_config_lines: + line_match = zone_re.match(line) + if line_match: + return line_match.group(1) + + return None + def cleanup_vifs(self): """ Xend does not remove vif when backend domain is down, so we must do it @@ -704,6 +717,12 @@ class QubesVm(object): "{0}/qubes_secondary_dns".format(domain_path), self.netvm_vm.secondary_dns) + tzname = self.get_timezone() + if tzname: + xs.write('', + "{0}/qubes-timezone".format(domain_path), + tzname) + for srv in self.services.keys(): # convert True/False to "1"/"0" xs.write('', "{0}/qubes-service/{1}".format(domain_path, srv), diff --git a/vm-init.d/qubes_core b/vm-init.d/qubes_core index 5050816f..eb02e770 100755 --- a/vm-init.d/qubes_core +++ b/vm-init.d/qubes_core @@ -29,6 +29,13 @@ start() (grep -v "\<$name\>" /etc/hosts; echo "127.0.0.1 $name") > /etc/hosts fi + timezone=`/usr/bin/xenstore-read qubes-timezone 2> /dev/null` + if [ -n "$timezone" ]; then + ln -f /usr/share/zoneinfo/$timezone /etc/localtime + echo "# Clock configuration autogenerated based on Qubes dom0 settings" > /etc/sysconfig/clock + echo "ZONE=\"$timezone\"" >> /etc/sysconfig/clock + fi + # Set IP address again (besides action in udev rules); this is needed by # DispVM (to override DispVM-template IP) and in case when qubes_ip was # called by udev before loading evtchn kernel module - in which case diff --git a/vm-systemd/qubes-sysinit.sh b/vm-systemd/qubes-sysinit.sh index 32d9a1a8..da13fafa 100755 --- a/vm-systemd/qubes-sysinit.sh +++ b/vm-systemd/qubes-sysinit.sh @@ -48,3 +48,9 @@ if [ -n "$name" ]; then (grep -v "\<$name\>" /etc/hosts; echo "127.0.0.1 $name") > /etc/hosts fi +timezone=`$XS_READ qubes-timezone 2> /dev/null` +if [ -n "$timezone" ]; then + ln -f /usr/share/zoneinfo/$timezone /etc/localtime + echo "# Clock configuration autogenerated based on Qubes dom0 settings" > /etc/sysconfig/clock + echo "ZONE=\"$timezone\"" >> /etc/sysconfig/clock +fi