Patchwork [bitbake-devel,1/1] toaster: fix timezone detection

login
register
mail settings
Submitter Alexandru DAMIAN
Date March 12, 2014, 1:41 p.m.
Message ID <1394631711-1083-1-git-send-email-alexandru.damian@intel.com>
Download mbox | patch
Permalink /patch/68527/
State New
Headers show

Comments

Alexandru DAMIAN - March 12, 2014, 1:41 p.m.
From: Alexandru DAMIAN <alexandru.damian@intel.com>

This patch replaces faulty timezone detection with a version
that simply reads the TZ environment variable if it is set.

This has been tested with the list of TZ values from
http://en.wikipedia.org/wiki/List_of_tz_database_time_zones

	[YOCTO #5499]

Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
---
 bitbake/lib/toaster/toastermain/settings.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Ross Burton - March 12, 2014, 4:06 p.m.
On 12 March 2014 13:41, Alex DAMIAN <alexandru.damian@intel.com> wrote:
> This patch replaces faulty timezone detection with a version
> that simply reads the TZ environment variable if it is set.

My Debian system doesn't have a TZ environment variable but does have
/etc/localtime which is the current timezone data. Yes, determining
the local timezone is a pain.  :)

Ross
Alexandru DAMIAN - March 12, 2014, 6:49 p.m.
This is a Debian-ism :(

Does toaster show you improper times, or refuses to start ?

Alex


On Wed, Mar 12, 2014 at 4:06 PM, Burton, Ross <ross.burton@intel.com> wrote:

> On 12 March 2014 13:41, Alex DAMIAN <alexandru.damian@intel.com> wrote:
> > This patch replaces faulty timezone detection with a version
> > that simply reads the TZ environment variable if it is set.
>
> My Debian system doesn't have a TZ environment variable but does have
> /etc/localtime which is the current timezone data. Yes, determining
> the local timezone is a pain.  :)
>
> Ross
> ---------------------------------------------------------------------
> Intel Corporation (UK) Limited
> Registered No. 1134945 (England)
> Registered Office: Pipers Way, Swindon SN3 1RJ
> VAT No: 860 2173 47
>
> This e-mail and any attachments may contain confidential material for
> the sole use of the intended recipient(s). Any review or distribution
> by others is strictly prohibited. If you are not the intended
> recipient, please contact the sender and delete all copies.
>
Ross Burton - March 12, 2014, 7:53 p.m.
On 12 March 2014 18:49, Damian, Alexandru <alexandru.damian@intel.com> wrote:
> This is a Debian-ism :(
>
> Does toaster show you improper times, or refuses to start ?

I've never tried Toaster, but I'm in GMT so I wouldn't be able to tell :)

It may be a Debianism but TZ isn't set at all so that's equally
unreliable.  I wonder what time.tznames is actually doing.

/etc/localtime was originally a Debianism but is also the canonical
file that systemd handles, so it's got a much wider install base now.
The similar file that Fedora has used to be /etc/sysconfig/clock.

http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/jana/trusty/view/head:/libjana-ecal/jana-ecal-utils.c#L113
is the first hit for some code I was involved in some time ago that
tried to work everywhere.  It's probably bitrotted quite dramatically
though...

Ross
Stanacar, StefanX - March 13, 2014, 7:40 a.m.
On Wed, 2014-03-12 at 16:06 +0000, Burton, Ross wrote:
> On 12 March 2014 13:41, Alex DAMIAN <alexandru.damian@intel.com> wrote:
> > This patch replaces faulty timezone detection with a version
> > that simply reads the TZ environment variable if it is set.
> 
> My Debian system doesn't have a TZ environment variable but does have
> /etc/localtime which is the current timezone data. Yes, determining
> the local timezone is a pain.  :)
> 
> Ross

FWIW, my Fedora 20 system doesn't have a TZ environment variable. It
uses the same /etc/localtime symbolic link as Debian.

Cheers,
Stefan
Paul Eggleton - March 13, 2014, 10:11 a.m.
On Wednesday 12 March 2014 18:49:02 Damian, Alexandru wrote:
> This is a Debian-ism :(

You say that, but the Fedora 20 install I have here (a) doesn't have TZ and 
(b) has /etc/localtime -> ../usr/share/zoneinfo/Europe/London. On my CentOS 
6.5 machine (possibly irrelevant for Toaster, but...) TZ is also unset but 
/etc/localtime is just a plain copy of some timezone file rather than a 
symlink. Older RH-style systems such as CentOS 6 have a ZONE value in 
/etc/sysconfig/clock but Fedora appears to have eliminated this file.

Given that, I don't think this is a complete fix.

Cheers,
Paul
Alexandru DAMIAN - March 13, 2014, 11:24 a.m.
I hear you, thanks for the input on various configurations.

Please do not submit this patch, I'll come back with a v2.

Ross, I tried time.tzname (as it currently stands) and it doesn't provide a
/usr/share/zoneinfo/ compatible name :(.

Alex


On Thu, Mar 13, 2014 at 10:11 AM, Paul Eggleton <
paul.eggleton@linux.intel.com> wrote:

> On Wednesday 12 March 2014 18:49:02 Damian, Alexandru wrote:
> > This is a Debian-ism :(
>
> You say that, but the Fedora 20 install I have here (a) doesn't have TZ and
> (b) has /etc/localtime -> ../usr/share/zoneinfo/Europe/London. On my CentOS
> 6.5 machine (possibly irrelevant for Toaster, but...) TZ is also unset but
> /etc/localtime is just a plain copy of some timezone file rather than a
> symlink. Older RH-style systems such as CentOS 6 have a ZONE value in
> /etc/sysconfig/clock but Fedora appears to have eliminated this file.
>
> Given that, I don't think this is a complete fix.
>
> Cheers,
> Paul
>
> --
>
> Paul Eggleton
> Intel Open Source Technology Centre
>

Patch

diff --git a/lib/toaster/toastermain/settings.py b/lib/toaster/toastermain/settings.py
index 51fa3cc..8be1851 100644
--- a/lib/toaster/toastermain/settings.py
+++ b/lib/toaster/toastermain/settings.py
@@ -51,8 +51,10 @@  ALLOWED_HOSTS = []
 # In a Windows environment this must be set to your system time zone.
 
 # Always use local computer's time zone
-import time
-TIME_ZONE = time.tzname[0]
+TIME_ZONE = "posix/GMT-0"               # have a sane default
+import os
+if 'TZ' in os.environ:
+    TIME_ZONE = os.environ['TZ']
 
 # Language code for this installation. All choices can be found here:
 # http://www.i18nguy.com/unicode/language-identifiers.html