Bug 196316 - kcmdatetimehelper does not set time zone correctly
Summary: kcmdatetimehelper does not set time zone correctly
Status: RESOLVED FIXED
Alias: None
Product: systemsettings
Classification: Applications
Component: kcm_clock (show other bugs)
Version: unspecified
Platform: Ubuntu Unspecified
: NOR normal
Target Milestone: ---
Assignee: Paul Campbell
URL:
Keywords:
: 197861 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-06-13 12:09 UTC by Constantin Berzan
Modified: 2015-02-27 19:02 UTC (History)
9 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Always update /etc/timezone (997 bytes, patch)
2009-06-26 12:47 UTC, Pau Garcia i Quiles
Details
If /etc/timezone exists, update it (1023 bytes, patch)
2009-06-26 12:56 UTC, Pau Garcia i Quiles
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Constantin Berzan 2009-06-13 12:09:13 UTC
Version:            (using KDE 4.2.90)
Installed from:    Ubuntu Packages

kdebase/workspace/kcontrol/dateandtime/helper.cpp currently does the following thing:
if( zic found )
{
        call zic
}
else
{
        set /etc/timezone
        copy /etc/localtime
}

However the 'set /etc/timezone' bit should be done even if zic is found, because zic apparently does not update /etc/timezone.

Thanks.
Comment 1 Constantin Berzan 2009-06-25 20:16:49 UTC
*** Bug 197861 has been marked as a duplicate of this bug. ***
Comment 2 Jacopo De Simoi 2009-06-25 21:22:50 UTC
I am dumping here some findings we made in IRC:

I can confirm that removing the "else" statement in the code, the timezone is correctly updated in this case even if I have "zic"

Apparently the same code works if neither "zic" nor "/etc/timezone" are present, but allows to change the timezone only once; only wiping $KDEHOME/share/config/ktimezonedrc entry allows to reset it.

finally, the existence of /etc/timezone or zic seems to be very much distro-dependent, so this complicate things further..
Comment 3 Pau Garcia i Quiles 2009-06-26 11:59:33 UTC
(On Kubuntu Hardy with KDE trunk 4.3.60)

zic is installed (part of the libc6 package, so it's always installed)

/etc/timezone exists and contains "Europe/Madrid"

/etc/localtime exists and is a copy of /usr/share/zoneinfo/Europe/Madrid

$KDEHOME/share/config/ktimezonerc exists and contains:

[TimeZones]
LocalZone=Europe/Madrid
ZoneinfoDir=/usr/share/zoneinfo
Zonetab=/usr/share/zoneinfo/zone.tab
ZonetabCache=


Initial situation: my timezone is "Europe/Madrid (CEST)" according to System Settings - Date and Time

Now I change it to something else, for instance Asia/Qatar, click Apply and enter the password for the kcmdatetimehelper:
- zic is invoked
- /etc/localtime is now a copy of /usr/share/zoneinfo/Asia/Qatar
- /etc/timezone is NOT changed
- $KDEHOME/share/config/ktimezonerc has NOT changed
- Date and Time still shows "Europe/Madrid (CEST)"

If I close the Date and Time window (for instance, clicking Back) and reopen it, it now says my timezone is "Europe/Madrid (AST)".
Comment 4 Pau Garcia i Quiles 2009-06-26 12:06:37 UTC
Follow-up from comment #3:

(On Kubuntu Hardy with KDE trunk 4.3.60)

I rename /usr/sbin/zic to /usr/sbin/zic- so that KStandardDirs::findExe( "zic" ) does not find it, thus falling into the else:

        else
        {
            QFile fTimezoneFile("/etc/timezone");

            if (fTimezoneFile.open(QIODevice::WriteOnly | QIODevice::Truncate) )
            {
                QTextStream t(&fTimezoneFile);
                t << selectedzone;
                fTimezoneFile.close();
            }

            if (!QFile::remove("/etc/localtime"))
            {
                ret |= ERROR_TZONE;
            }
            else
                if (!QFile::copy(tz,"/etc/localtime"))
                    ret |= ERROR_TZONE;
        }

        QString val = ':' + tz;

/etc/timezone exists and contains "Europe/Madrid". There is a LF at the end of the line.

/etc/localtime exists and is a copy of /usr/share/zoneinfo/Europe/Madrid

$KDEHOME/share/config/ktimezonerc exists and contains:

[TimeZones]
LocalZone=Europe/Madrid
ZoneinfoDir=/usr/share/zoneinfo
Zonetab=/usr/share/zoneinfo/zone.tab
ZonetabCache=


Initial situation: my timezone is "Europe/Madrid (CEST)" according to System
Settings - Date and Time

Now I change it to something else, for instance Asia/Qatar, click Apply and
enter the password for the kcmdatetimehelper:
- zic is NOT invoked
- /etc/localtime is now a copy of /usr/share/zoneinfo/Asia/Qatar
- /etc/timezone has changed to Asia/Qatar. There is no LF at the end of the line.
- $KDEHOME/share/config/ktimezonerc has changed to:

[TimeZones]
LocalZone=Asia/Qatar
ZoneinfoDir=/usr/share/zoneinfo
Zonetab=/usr/share/zoneinfo/zone.tab
ZonetabCache=

- Date and Time still shows "Europe/Madrid (CEST)"

If I close the Date and Time window (for instance, clicking Back) and reopen
it, it now says my timezone is "Asia/Qatar (AST)".
Comment 5 Pau Garcia i Quiles 2009-06-26 12:47:00 UTC
Created attachment 34824 [details]
Always update /etc/timezone

This patch fixes the issue for me (Kubuntu)
Comment 6 Pau Garcia i Quiles 2009-06-26 12:52:14 UTC
Comment on attachment 34824 [details]
Always update /etc/timezone

>Index: helper.cpp
>===================================================================
>--- helper.cpp	(revision 987554)
>+++ helper.cpp	(working copy)
>@@ -170,15 +170,6 @@
>         }
>         else
>         {
>-            QFile fTimezoneFile("/etc/timezone");
>-
>-            if (fTimezoneFile.open(QIODevice::WriteOnly | QIODevice::Truncate) )
>-            {
>-                QTextStream t(&fTimezoneFile);
>-                t << selectedzone;
>-                fTimezoneFile.close();
>-            }
>-
>             if (!QFile::remove("/etc/localtime"))
>             {
>                 ret |= ERROR_TZONE;
>@@ -188,6 +179,15 @@
>                     ret |= ERROR_TZONE;
>         }
> 
>+        QFile fTimezoneFile("/etc/timezone");
>+
>+        if (fTimezoneFile.open(QIODevice::WriteOnly | QIODevice::Truncate) )
>+        {
>+            QTextStream t(&fTimezoneFile);
>+            t << selectedzone;
>+            fTimezoneFile.close();
>+        }
>+
>         QString val = ':' + tz;
> #endif // !USE_SOLARIS
>
Comment 7 Pau Garcia i Quiles 2009-06-26 12:56:39 UTC
Created attachment 34826 [details]
If /etc/timezone exists, update it

If /etc/timezone exists (for instance, on Debian and its derivatives), update it irregardless of zic being present or not. This fixes the issue on Kubuntu for me. I have not tested on /etc/timezone-lacking distributions such as Mandriva and Gentoo.
Comment 8 Jacopo De Simoi 2009-06-26 21:07:23 UTC
(In reply to comment #7)
> Created an attachment (id=34826) [details]
> If /etc/timezone exists, update it
> 
> If /etc/timezone exists (for instance, on Debian and its derivatives), update
> it irregardless of zic being present or not. This fixes the issue on Kubuntu
> for me. I have not tested on /etc/timezone-lacking distributions such as
> Mandriva and Gentoo.

Gentoo indeed switched to /etc/timezone some time ago. Current installs have it there.
Comment 9 Pau Garcia i Quiles 2009-06-26 21:30:58 UTC
openSuse 11.1, KDE 4.2.3
- zic is present (/usr/sbin/zic)
- /etc/timezone is not present
- /etc/localtime is a copy of a file from /usr/share/zoneinfo

Changing the timezone in System Settings - Date and Time works fine the first time. From then on, /etc/localtime is updated fine but ktimezonedrc is not updated. Creating /etc/timezone changes nothing.

I have not tested my patch against openSuse because I don't know how to rebuild packages and I don't want to install KDE trunk and the plethora of development packages ir requires (it's my gf's laptop :-)
Comment 10 Pau Garcia i Quiles 2009-06-26 21:37:39 UTC
Arch Linux, KDE 4.2.4
- /usr/sbin/zic present
- /etc/timezone not present
- /etc/localtime is a copy of a file from /usr/share/zoneinfo
- Time zone is defined in /etc/rc.conf by means of the TIMEZONE variable:
    HARDWARECLOCK="UTC"
    TIMEZONE="Europe/Madrid"

Changing timezone in System Settings - Date and Time does NOT update /etc/localtime or ktimezonedrc at all. Not even once.
Comment 11 Albert Astals Cid 2009-07-08 17:29:22 UTC
Following Pau's request for info:
Distro: Fedora 11
zic -> /usr/sbin/zic
/etc/timezone -> No
/etc/localtime -> Yes, hard link
zoneinfo files -> /usr/share/zoneinfo/
TZ env var -> No
TIMEZONE env var -> No
Linux kernel -> 2.6.29.5-191.fc11.i586
inotify -> No

I'm not sure if it works or not on my system (using trunk, somehow i managed to change it to America/Manaus but now i can't change it to something else)
Comment 12 Casper van Donderen 2009-07-08 17:35:05 UTC
OpenSuSE 11.1 KDE 4.3 RC1 & KDE trunk
- /usr/sbin/zic present
- /etc/timezone not present. SuSE uses /etc/sysconfig/clock
- /etc/localtime is hard link
- zoneinfo files in /usr/share/zoneinfo
- No TZ & no TIMEZONE env variable.
- uname -a : Linux X61-tablet 2.6.27.23-0.1-pae #1 SMP 2009-05-26 17:02:05
-0400 i686 i686 i386 GNU/Linux
- No inotify present.
Comment 13 Paul Adams 2009-07-08 17:38:40 UTC
Distro: Mandriva Free 2009.1
zic -> /usr/sbin/zic
/etc/timezone -> Yes
/etc/localtime -> Yes
-- -rw-r--r-- 1 root root 3661 2009-07-02 07:59 /etc/localtime
zoneinfo files -> /usr/share/zoneinfo/
TZ env var -> No
TIMEZONE env var -> No
uname -a -> Linux amoeba 2.6.29.3-desktop-1mnb #1 SMP Thu May 14 14:14:48 EDT
2009
i686 Intel(R) Atom(TM) CPU N270   @ 1.60GHz GNU/Linux
inotify -> No
Comment 14 David Jarvie 2009-07-08 17:44:02 UTC
OpenSUSE 11.1: contents of /etc/sysconfig/clock include a TIMEZONE line, e.g.

TIMEZONE="Europe/Madrid"
Comment 15 Albert Astals Cid 2009-07-08 17:56:49 UTC
It's me again, Fedora 11 also has

cat /etc/sysconfig/clock
# The ZONE parameter is only evaluated by system-config-date.
# The time zone of the system is defined by the contents of /etc/localtime.
ZONE="Europe/Madrid"
Comment 16 Rafael Fernández López 2009-07-08 17:58:01 UTC
BOF request for info:

1. Linux archlinux 2.6.30-ARCH
2. /usr/sbin/zic
3. No /etc/timezone
4. Have /etc/localtime
    4.1 It is a regular file
5. /usr/share/zoneinfo exists and is correct
6. No TZ environment variable
7. No TIMEZONE environment variable
8. Linux archlinux 2.6.30-ARCH #1 SMP PREEMPT Sat Jul 4 11:13:08 UTC 2009 i686 Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz GenuineIntel GNU/Linux

cat /usr/src/linux-2.6.30-ARCH/.config | grep -i inotify says:
CONFIG_INOTIFY=y
CONFIG_INOTIFY_USER=y
CONFIG_AUFS_HINOTIFY=y
Comment 17 groot 2009-07-08 17:59:47 UTC
Solaris Nevada build 115.
zic is /usr/sbin/zic 
no /etc/timezone
no /etc/localtime
zoneinfo is in /usr/share/lib/zoneinfo/
$TZ is set to Europe/Amsterdam (zoneinfo/$TZ exists and is a regular file)
no $TIMEZONE is set

The system timezone is set by /etc/TIMEZONE, which is a symlink to
/etc/default/init and which contains shell-style variable-assignment lines of
the form VAR=VALUE. One of the lines is TZ=<zone>. Editing this file changes
the system timezone, but needs a reboot. Setting TZ variable by hand changes
date(1) output.
Comment 18 Mark 2009-08-05 15:00:40 UTC
i confirm this bug on my system, kde 4.3.0
zic exists and /etc/timezone doesnt.

I have Region set to Czech(central Europe) and my timezone defaults to Bratislava/Slovakia/Central Europe. When I change it to Prague/Czech..it doesnt work.
Comment 19 Ladislav Nesnera 2010-01-28 19:52:54 UTC
At first glance, this post (https://bugs.kde.org/show_bug.cgi?id=168400#c6) could solve this problem, or not?
Comment 20 David Jarvie 2010-01-28 21:19:28 UTC
Detection of the local system time zone has been improved - see commits 1044550, 1044096, 1044097 (KDE 4.3 branch). More extensive changes to read more local time zone storage methods for different distros were made in trunk (which will be in KDE 4.4) by commit 1044547. So check whether the bug still exists in KDE 4.4 - it may be fixed.
Comment 21 David Faure 2010-04-30 14:07:51 UTC
Can someone also review the patch that was sent to kde-core-devel by sycao on 2009-08-10?
"Re: [PATCH] set up and update timezone in clock config module"

It fixes:
> 1. currentZone doesn't update effectively after timezone changed.
> 2. ntp server list is translated, and can not be treated correctly by kcmdatetimehelper.
Comment 22 David Edmundson 2015-02-27 19:02:37 UTC
Git commit b6ae01ca8ea776c97cc57836401ca9696e2529e8 by David Edmundson.
Committed on 14/02/2015 at 13:50.
Pushed by davidedmundson into branch 'master'.

Add systemd support into the clock KCM as an optional dependency

The current time setting helper is incredibly broken.

It manually tries to run a range of NTP utilities, all of which are
deprecated.

We can just call timedated directly and cut out the middleman as it has
uses polkit anyway.

This is currently an optional dependency, and the original helper still
exists. It makes the code messy, but we have users to support for now.

Detection is done at runtime
Related: bug 311286, bug 317784, bug 319072, bug 337012, bug 339582, bug 241817, bug 178968, bug 320456, bug 317999, bug 337659
REVIEW: 122400

M  +5    -1    kcms/dateandtime/CMakeLists.txt
M  +22   -12   kcms/dateandtime/dateandtime.ui
M  +44   -30   kcms/dateandtime/dtime.cpp
M  +2    -1    kcms/dateandtime/dtime.h
M  +80   -7    kcms/dateandtime/main.cpp
M  +5    -1    kcms/dateandtime/main.h
A  +43   -0    kcms/dateandtime/timedated1.xml

http://commits.kde.org/plasma-desktop/b6ae01ca8ea776c97cc57836401ca9696e2529e8