EdgeRouter Lite & EdgeRouter 4: date command ignores timezone, shows UTC

You should be able to set it by rebooting, or with
/etc/init.d/system reload

root@router1:~# cat /tmp/TZ
EET-2EEST,M3.5.0/3,M10.5.0/4
root@router1:~# rm /tmp/TZ
root@router1:~# date
Thu Dec 10 21:08:32 UTC 2020
root@router1:~# /etc/init.d/system reload
root@router1:~# date
Thu Dec 10 23:08:44 EET 2020
root@router1:~#

Weird, something going wrong there then (on multiple devices). I already tried switching to another time zone and back, both in LuCI and over SSH, to no avail.

There's definitely some weirdness going on:

root@OpenWrt:~# echo 'CET-1CEST,M3.5.0,M10.5.0/3' > /tmp/TZ 
root@OpenWrt:~# date
Thu Dec 10 21:07:57 UTC 2020
root@OpenWrt:~# service system reload
root@OpenWrt:~# date
Thu Dec 10 21:08:34 UTC 2020
root@OpenWrt:~# /etc/init.d/system reload
root@OpenWrt:~# date
Thu Dec 10 21:09:31 UTC 2020
root@OpenWrt:~# ls -l /tmp/TZ
ls: /tmp/TZ: No such file or directory

After removing /tmp/TZ myself and doing another full run of it:

root@OpenWrt:~# ls /tmp/TZ
ls: /tmp/TZ: No such file or directory
root@OpenWrt:~# echo 'CET-1CEST,M3.5.0,M10.5.0/3' > /tmp/TZ 
root@OpenWrt:~# ls /tmp/TZ
/tmp/TZ
root@OpenWrt:~# /etc/init.d/system reload
root@OpenWrt:~# ls /tmp/TZ
ls: /tmp/TZ: No such file or directory
root@OpenWrt:~# date
Thu Dec 10 21:10:59 UTC 2020

For me it works ok, also on a device with master built today:
(and with the the default C lib, musl)

 OpenWrt SNAPSHOT, r15182-8663072854
 -----------------------------------------------------

root@router3:~# cat /tmp/TZ
EET-2EEST,M3.5.0/3,M10.5.0/4
root@router3:~# date -u
Thu Dec 10 21:14:32 UTC 2020
root@router3:~# date
Thu Dec 10 23:14:35 EET 2020
root@router3:~#
root@router3:~# rm /tmp/TZ
root@router3:~# date -u
Thu Dec 10 21:14:47 UTC 2020
root@router3:~# date
Thu Dec 10 21:14:48 UTC 2020
root@router3:~#
root@router3:~# /etc/init.d/system reload
root@router3:~#
root@router3:~# cat /tmp/TZ
EET-2EEST,M3.5.0/3,M10.5.0/4
root@router3:~# date -u
Thu Dec 10 21:15:06 UTC 2020
root@router3:~# date
Thu Dec 10 23:15:08 EET 2020

Yeah I don't know what's happening here.

  • On my ER4, /tmp/TZ is not there. Time displays in UTC. Master build from December 9th.
  • On my GS1900-10HP, /tmp/TZ is there. Time displays in CET. Same master build from December 9th.
  • On my RT-AC57U, /tmp/TZ is not there. Time displays in CET. Master build from December 3rd.
  • On my EA6350v3, /tmp/TZ is not there. Time displays in CET. Same master build from December 9th.

Two ideas:

Have you installed the zoneinfo packages on the device that fails?
Do you have /tmp/localtime there?
(as that would lead to deleting /tmp/TZ. See /etc/init.d/system for reference, or the message that I referenced above)

Somehow misformatted /etc/config/system
(but that should not affect the situation when you manually change /tmp/TZ)

I do. Version 2020d-1.

I do:

# ls -l /tmp/localtime 
lrwxrwxrwx    1 root     root            35 Dec 10 21:10 /tmp/localtime -> /usr/share/zoneinfo/Europe/Brussels

I removed the symlink now (and /tmp/localtime as well), reloaded the system service, but no difference.

I already copied a working config off another system and same issue. So I don't think that's at play, no.

I will reboot the system sometime tonight, and see what's going on tomorrow.

Well, then there shouldn't be any /tmp/TZ as the info from the full zoneinfo is used via /tmp/localtime symlink.

So here I am again :smile: I removed /etc/TZ, linked /etc/localtime to /usr/share/zoneinfo/ and rebooted. Still UTC though :roll_eyes:

Typo?
/tmp/localtime

See the init script above.

I guess that something goes wrong with the full zoneinfo data. Do you really need the full zoneinfo for something?

It's both in /etc/ and /tmp, the symlink. I removed the one in /etc, reloaded the system service, no difference.

I don't need the full zoneinfo, if you say OpenWrt has everything onboard by default, I'll run a build without and check again.

Musl & busybox have the capability to apply the POSIX string included in the config file. But some advanced apps (like php, real webservers, some python apps) might want the full zoneinfo, if they want direct access to all timezones.

zoneinfo is rarely installed.

Please read the explanation from the message that I linked above.

@hnyman Sorry for being a bit dense. At this point, all my builds have zoneinfo removed. There's no /tmp/localinfo either. Just /etc/TZ linking to a (now present) /tmp/TZ. But the time is still printed in UTC no matter what (timezone's set like before).

# cat /etc/config/system 

config system
	option hostname 'OpenWrt'
	option ttylogin '0'
	option log_size '64'
	option urandom_seed '0'
	option log_proto 'udp'
	option conloglevel '8'
	option cronloglevel '5'
	option zonename 'Europe/Brussels'
	option timezone 'CET-1CEST,M3.5.0,M10.5.0/3'

[...]

What I did notice, however, is that on my EdgeRouter Lite I set up today, the same thing is happening. Another octeon device showing UTC. My UCI defaults scripts set up a Europe/Brussels timezone at first installation, and on all my other devices that works like a charm. Looks like something else is at play here...

Perhaps one of your devices have utils/zoneinfo installed?

If you read back, I think we already covered that intensively. Like I said, I have two Octeon devices and they're both exhibiting it. All my other hardware (ath79, mt7621, x86/64, ...) prints local time without complaining.

No all of them have it removed. My ath79 / ipq40xx / mt7621 / realtek devices all show CET correctly. It's just the Octeon devices deviating.

All of them use the same config settings concerning time etc.

Does any of them have a real real-time clock?

Thought about that too but shouldn't there be a /dev/misc/rtc then? Because that's missing. I do see the boot log printing "Switched to clocksource OCTEON_CVMCOUNT" (see opening post). When I look that up online I get:

"The clocksource concept represents the generic API for clock sources management in the Linux kernel."

Found this BSD mailing list thread though and that suggests the EdgeRouter Lite at least doesn't have one.

I don't see any battery either on the EdgeRouter Lite board (picture of the original version, courtesy of SmallNetBuilder):

Edit: I did find this old OpenWrt bug that seems related (and seems to rear its head once in a while), but no conclusive solution here. Already tried the busybox date -k command as well as removing/reloading the xt_time module, still UTC.

I can override the timezone Busybox uses by issuing TZ=CET date, but that's just a workaround. env prints no TZ value though, not on a functional system, nor on the EdgeRouters. So that's not the issue. The output looks identical on both systems as well.

Nope, TZ=CET doesn't seem to help one bit.

Hi

I have the same problem on EdgeRouter Lite 3 with OpenWrt 19.07.7.

I used strace tool to track which system calls were made.

3 lines of output show what is wrong:

strace date

...
open("/etc/TZ", O_RDONLY|O_NONBLOCK|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=27, ...}) = 0
mmap(NULL, 6953200402636640000, PROT_READ, MAP_SHARED, 3, 0) = -1 ENOMEM (Out of memory)
...

Second parameter of mmap function should be 27 (st_size from fstat function)
instead of 6953200402636640000,
so date can't read content of TZ file.

Now, I have no spare time to look at source files, but maybe someone could do that.

Some tips:
fstat() vs. fstat64()?
type casting?

Regards

3 Likes

I just took a look on mine, and the contents of /etc/TZ (symlink to /etc/localtime, which is symlink to /tmp/localtime) are quite a mess.

On another OpenWrt device (non-octeon) the content of TZ is what I expect: ("EST5EDT,M3.2.0,M11.1.0")

Editing /tmp/localtime and fixing its contents didn't help the 'date' command work (and would be lost on restart), but it looks like the problem also exists in whatever code writes out the /tmp/localtime file, too.