/etc/localtime dumb, log different timezones

I see that /etc/localtime is symlink to /tmp/localtime which does not exist:

# ls -l /etc/localtime
lrwxrwxrwx    1 root     root            14 May 15 10:20 /etc/localtime -> /tmp/localtime
# ls -l /tmp/localtime
ls: /tmp/localtime: No such file or directory

I have logs with multiple timezones:

May 20 07:59:01 gw /usr/sbin/cron[18291]: (root) CMD (/usr/bin/rainbow_button_sync.sh)
May 20 09:59:21 gw kernel: [430381.451226] mv88e6085 f1072004.mdio-mii:10 lan3: Link is Up - 1Gbps/Full - flow control off
May 20 09:59:21 gw kernel: [430381.459716] br-lan: port 4(lan3) entered blocking state
May 20 09:59:21 gw kernel: [430381.465056] br-lan: port 4(lan3) entered forwarding state
May 20 07:59:21 gw netifd: Network device ‘lan3’ link is up

Is this expected behaviour?

The symlink is expected for the build toolchain of glibc git.openwrt.org Git - openwrt/openwrt.git/blob - package/libs/toolchain/Makefile

What is unexpected is the absence of /tmp/localtime, that should been generated according to git.openwrt.org Git - openwrt/openwrt.git/blob - package/base-files/files/etc/init.d/system

but then /usr/share/zoneinfo/$zonename does not seem been generated and could be a bug.

It seems to be known issue syslog-ng time is in UTC, not localtime (#471) · Issues · Turris / Turris OS / Turris OS packages · GitLab

It is not a bug but a missing package, installing zoneinfo-core seems to remedy the issue - the missing symlink as well as the timestamps in the logs.

I have installed zoneinfo-core, after install nor reboot /tmp/localtime does not exist. I have set

/etc/config/system: option zonename ‘Europe/Bratislava’

and the /etc/init.d/system script searches for /usr/share/zoneinfo/$zonename

My zone is contained in zoneinfo-europe package. After installing this and running /etc/init.d/system start /tmp/localtime exists, but cron logs are still in UTC
… I’ll reboot again and post the result

Set it via LuCI as it will generate the corresponding timezone and then reboot. Have tried with various zones and it worked, i.e. after the reboot the symlink always been present and no discrepancies in syslog’s timestamps.

The only setting where the symlink is absent is with UTC which is logical.

I have tried that, but the result is the same:

# ls -l /etc/localtime /tmp/localtime /etc/config/system
-rw-------    1 root     root           455 May 21 21:02 /etc/config/system
lrwxrwxrwx    1 root     root            14 May 15 10:20 /etc/localtime -> /tmp/localtime
lrwxrwxrwx    1 root     root            37 May 21 21:02 /tmp/localtime -> /usr/share/zoneinfo/Europe/Bratislava

which means, I still need to have zoneinfo-europe package installed.
Should I expect different results without the package, or will luci install it for me?

Which version of TurrisOS are you running?
I am in version 3 and the timezone is on /tmp/TZ, and /etc/TZ is a symlink.
Still the above method didn’t work for me.

It’s 4.0.5 and TZ is different file than localtime. TZ is removed if zonename exists:

echo "$timezone" > /tmp/TZ
[ -n "$zonename" ] && [ -f "/usr/share/zoneinfo/$zonename" ] && \
        ln -sf "/usr/share/zoneinfo/$zonename" /tmp/localtime && rm -f /tmp/TZ

so now I have dangling symlink /etc/TZ:

# ls -l  /etc/TZ /tmp/TZ
ls: /tmp/TZ: No such file or directory
lrwxrwxrwx    1 root     root             7 May 15 10:20 /etc/TZ -> /tmp/TZ

and times are still inconsistent:

May 22 10:34:40 gw kernel: [  100.376726] br-lan: port 7(wlan0) entered forwarding state
May 22 08:34:40 gw hostapd: wlan0: interface state DFS->ENABLED
1 Like

hi all, same issue here. Installing zoneinfo-core & reboot did not help. Is there anything else to run / install, please?

See if installing the logger package and reboot makes a difference, it would replace the busybox logger applet that might be the underlying cause.

I am in europe, my localtime is Europe/Bratislava which is contained in zoneinfo-europe. installing zoneinfo-core does not help.

Thanks for tip.
I have tried this, did not help. at least for daemons like cron, restarting which did not help even.

TOS 5.0.3 currently.

1 Like

There are some programs that show proper time:


but the rest doesn’t seem to.

Such userland may log Unix time (timezone-independent time representation) only.

Unless there would be specific log options for such userland it might be possible to rectify such sources with syslog-ng’s options:

Ultimately I have modified the etc/syslog-ng.conf with:

destination messages {
        file("/var/log/messages" suppress(5) template("${R_YEAR}-${R_MONTH}-${R_DAY} ${R_HOUR}:${R_MIN}:${R_SEC} ${PRIORITY} ${PROGRAM}[${PID}]: ${MSGONLY}\n") log_fifo_size(256)); 

Afterwards the output timestamps in system log are aligned (but apparently this is not solving the root cause of the issue, only the output formatting).

And probably needs to be manually re-applied after each update.

Solution found in this topic: Time difference is System log

it doesn’t:

root@blah:/etc# strace -p 15346
strace: Process 15346 attached
clock_gettime(CLOCK_REALTIME, {tv_sec=1594745701, tv_nsec=173116254}) = 0
getpid()                                = 15346
sendto(7, "<27>Jul 14 16:55:01 odhcp6c[1534"..., 99, 0, NULL, 0) = 99

odhcp6c FYI

That seems rather a case in point, though it is not even clear whether the strace snippet refers to userland’s logging or some bit of other operation. Best to my understanding:

CLOCK_REALTIME clock measures the amount of time that has elapsed since Epoch time (aka Unix time) which is 00:00:00 January 1, 1970 Greenwich Mean Time (GMT)

= 50.53444181 y | 2,637 w | 18,458 d | 442,985 hrs

It’s logging at GMT+12? :face_with_raised_eyebrow: Seems quite far from Bratislava…

$ env TZ= date --date='@1594745701'
Tue 14 Jul 2020 04:55:01 PM UTC

… yes, all UN*X systems use time in seconds from epoch, and convert to local time when needed. the:

is the data sent to syslog socket. it’s in UTC, not in local time.
my local time is in CEST so that should be 2 hours more.

lrwxrwxrwx    1 root     root            14 Jul  7 03:13 /etc/localtime -> /tmp/localtime
lrwxrwxrwx    1 root     root            37 Jul 11 15:55 /tmp/localtime -> /usr/share/zoneinfo/Europe/Bratislava

even date reports:

root@blah:~# date
Tue Jul 14 20:30:27 CEST 2020

more when coded to, apparently it does call only CLOCK_REALTIME and logically logs in UTC, would be different if the userland would call date. Likely the same with other userland you mentioned, e.g. cron.

In which case the log daemon (syslog-ng) would need to be configured to adjust the source entries to the correct TZ.

the syslog() is a C library function that is supposed to log current time in local timezone. Somehow it does not check for local timezone.
This can be considered a bug