You are not logged in.

#1 2012-01-07 17:27:47

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 876

[SOLVED] Wrong UTC time settings?

I'm facing a strange problem with UTC time, maybe I don't understand what is the meaning of UTC time but anyway I can't fix this on my own. My locale configuration is:

LOCALE="it_IT.utf8"
DAEMON_LOCALE="no"
HARDWARECLOCK="UTC"
TIMEZONE="Europe/Rome"

and my hardware clock says:

$ hwclock
sab 07 gen 2012 17:23:03 CET  -0.609866 secondi

Since I live in the GMT+1 time zone (Europe/Rome) I was expecting that system clock would be set to 18:23:03, instead at boot it always has the same time as hwclock, until ntp fix things after a while. But at successive reboots, the history repeats. This is my daemons line:

DAEMONS=(syslog-ng @cpufreq network netfs crond dbus @cupsd @ntpd)

What's wrong in my configuration? Or maybe it works as expected and I didn't understand the expected behavior?
Thanks.

Last edited by snack (2012-02-05 11:18:27)

Offline

#2 2012-01-08 00:24:26

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] Wrong UTC time settings?

Offline

#3 2012-01-08 11:37:04

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 876

Re: [SOLVED] Wrong UTC time settings?

Thanks, I really don't understand much about that discussion but I hope devs can fix this.

Offline

#4 2012-01-08 11:58:45

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 876

Re: [SOLVED] Wrong UTC time settings?

I really can't understand this:

$ hwclock --localtime
dom 08 gen 2012 10:56:17 CET  -0.442359 secondi
$ hwclock --utc
dom 08 gen 2012 11:56:21 CET  -0.676715 secondi

Given my timezone (Europe/Rome) I would expect utc=11:56 localtime=12:56...

Offline

#5 2012-01-08 12:20:10

Kodama
Member
Registered: 2009-11-02
Posts: 53

Re: [SOLVED] Wrong UTC time settings?

I can't say anything to help you but I'm glad that I'm not the only one with this bug;

[andreas@myhost ~]$ hwclock --localtime
So 08 Jan 2012 13:16:22 CET  -0.875533 Sekunden
[andreas@myhost ~]$ hwclock --utc
So 08 Jan 2012 14:16:31 CET  -0.844310 Sekunden

I was beginning to think this might have something to do with my firewall not letting sync ntp but that's fortunately not the case...
As always we need to wait until it's fixed...which pretty much describes my whole Linux experience for nearly 4 years now...you alway wait for something to finally work wheather it's an xorg issue, a graphic driver thing, etc, etc, etc...


Greets
Andreas

Last edited by Kodama (2012-01-08 12:21:30)

Offline

#6 2012-01-08 13:31:11

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 876

Re: [SOLVED] Wrong UTC time settings?

I'm not sure it is a bug, rather I think that there's something I don't understand in how Linux handles rtc, utc, system clock and all that... I hope someone with greater knowledge than me would clarify some of these points.

Offline

#7 2012-01-08 17:16:21

alexkarro
Member
Registered: 2012-01-02
Posts: 31

Re: [SOLVED] Wrong UTC time settings?

I had the same issue but I fixed it by setting up the ntpd daemon correctly using the server informaton from http://www.ntp.org/, syncing ntpd -q and then using hwclock --systohc.

I'm on UTC and Europe/Amsterdam, no problems.

Last edited by alexkarro (2012-01-08 17:19:46)

Offline

#8 2012-01-09 14:31:04

stqn
Member
Registered: 2010-03-19
Posts: 1,191
Website

Re: [SOLVED] Wrong UTC time settings?

I solved my clock problems by running hwclock "manually" in rc.local. I think I already explained it in another post, but anyway...

1) set your clock correctly, then run "hwclock --systohc --utc"
2) add "hwclock --hctosys" in /etc/rc.local
3) (if running openntpd which does not update the hwclock) add "hwclock --systohc" in /etc/rc.shutdown.local
4) make sure you have the ntpd (or openntpd) daemon in /etc/rc.conf (in fact I'm also running openntpd from rc.local so that it is run right after network is available). Also make sure you're _not_ running the hwclock daemon.

If for some reason you want to switch to localtime you just have to replace "--utc" with "--localtime" in step 1) (at least with openntpd). Whether your hw clock was stored in UTC or in localtime is stored in /var/lib/hwclock/adjtime.

Edit: several edits, please re-read everything wink.

Edit 2: I see that /etc/rc.sysinit actually sets the clock with "--systz" ("set the system time based on the current timezone") and uses the HARDWARECLOCK variable...

hwclock's man page wrote:

This is an alternate option to --hctosys that does not read  the
              hardware  clock,  and  may be used in system startup scripts for
              recent 2.6 kernels where you know the System Time  contains  the
              Hardware Clock time.

Not sure what's the point.

Last edited by stqn (2012-01-09 14:53:18)

Offline

#9 2012-01-09 14:41:24

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 876

Re: [SOLVED] Wrong UTC time settings?

Thaks everybody for the answers. Apart from making my system work, I'd like to understand what is the meaning of having hwclock set to utc or localtime. Being not an expert at all, I naively thoght that HARDWARECLOCK="UTC" means: set the hwclock to GMT, no matter where in the world you are; then, according to your timezone (set in rc.conf, for me it is Europe/Rome), system clock will be set accordingly on boot by the kernel (for me, it would be sysclock=hwclock+1hour); ntpd may eventually make fine adjustments to sysclock if it is running, then on shutdown it will sync hwclock (for me, hwclock=sysclock-1). Conversely, "LOCALTIME" would mean hwclock=sysclock.
Something must be wrong in all this reasoning because setting HARDWARECLOCK="UTC" and hwclock to GMT makes my sysclok=hwclock=GMT, until ntpd corrects it to sysclok=hwclock+1hour (after some minutes after boot).

Offline

#10 2012-02-05 11:18:14

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 876

Re: [SOLVED] Wrong UTC time settings?

I think I found the solution: hwclock takes into account the locale when setting and reading the hardware clock. This means that one should set the hwclock to UTC not using the GMT but rather the local time. hwclock will automatically convert the localtime to UTC and set it. So if I live in GMT+1 time zone and my local time is 10:00, I should set hwclock to 10:00, and I guess the hardware clock will be effectively set to 9:00. Similarly, when reading the hardware clock the displayed time is converted to local time (you can verify it by changing the TZ environment variable to other time zones and see that the time displayed by hwclock changes accordingly, without setting the hardware clock).
Marking as solved, thanks everybody for the help.

Offline

Board footer

Powered by FluxBB