Where is etc/localtime

The following code throws an exception when it runs:

#!/usr/bin/env tclsh
#

set nextmonth [exec date +%Y%m];
append nextmonth "01";
set date2 [clock scan ${nextmonth} -format "%Y%m%d"];
set date2 [clock add $date2 1 month]
puts $nextmonth

This documentation makes the recommendation that Is a missing /etc/localtime but it’s a little more sensitive than that. I think they are expecting a symlink to the proper TZ file.

As a side note. This issue seems to be limited to the server version of ClearLinux since the /etc/localtime exists on my desktop.

Did you set the timezone with timedatectrl?

From the man page:

SYNOPSIS
timedatectl [OPTIONS…] {COMMAND}

COMMANDS

set-timezone [TIMEZONE]
Set the system time zone to the specified value. Available timezones can be listed with list-timezones. If the RTC is configured to be in the local time, this will also update the RTC time. This call will alter the /etc/localtime symlink. See localtime(5) for more information.

I did not set the TZ during or after the initial install. I reported my experience from tclsh having not corrected the problem as indicated in the tcl doc. I had not considered looking for timedatectl but glad to know it’s there… I think the issue is still important because the server and desktop installation are not in parity with respect to the TZ configuration.

It’s a required option in both the OS Desktop Installer and the OS Installer, but you might have used another method.

If you just left the default for the server installation on UTC and the installer uses the same calls as timedatectl for setting the timezone then no localtime symlink would have been created.

Demo time:

cd /etc
ls -l localtime
ls: cannot access ‘localtime’: No such file or directory
timedatectl set-timezone UTC
ls -l localtime
ls: cannot access ‘localtime’: No such file or directory
timedatectl set-timezone Europe/Amsterdam
ls -l localtime
lrwxrwxrwx 1 root root 38 Apr 15 23:24 localtime → …/usr/share/zoneinfo/Europe/Amsterdam
timedatectl set-timezone UTC
ls -l localtime
lrwxrwxrwx 1 root root 25 Apr 15 23:24 localtime → …/usr/share/zoneinfo/UTC

My guess is it’s more another quirk* from systemd (systemd-firstboot, timedatectl) than anything to do with the ClearLinux installers.

*) Why not create a link to …/usr/share/zoneinfo/UTC when setting the timezone to UTC when there is no /etc/localtime?
Why not remove the link when setting the timezone to UTC if it is set to a specific zone?

1 Like

that’s a great explanation… THANKS. And so back to my initial ticket… seems that tclsh depends on etc/localtime. Obviously I can create the link myself but from a system integrity POV having the installer do the right thing would be NICER.

PS: I wonder what the tclsh packager is doing and if not then is this an issue there?

In the stateless paradigm, instead tclsh should be recompiled to default to UTC itself if /etc/localtime doesn’t exist.

I suppose that’s option too, however, this issue is documented so changing tclsh could create inconsistent behavior … and frankly an explicit etc/localtime makes more sense otherwise one has to test the hardware clock… and about there I lose traction and have no idea which is the best resolution.

This makes it pass, but my TCL is too rusty to be sure it’s the best or even correct fix:

diff --git a/library/clock.tcl b/library/clock.tcl
index 273b5345c724..77641474d6d2 100644
--- a/library/clock.tcl
+++ b/library/clock.tcl
@@ -3001,7 +3001,7 @@ proc ::tcl::clock::GetSystemTimeZone {} {
                                    Tcl/Localtime /etc/localtime}] } {
             set timezone :Tcl/Localtime
         } else {
-            set timezone :localtime
+            set timezone :UTC
         }
        set CachedSystemTimeZone $timezone
     }

On an installed system, that’s /usr/lib/tcl8.6/clock.tcl.

1 Like