Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 938309 - Gentoo stages (incl. systemd stages) default to /etc/localtime as a file, whil sys-apps/systemd expects a symlink
Summary: Gentoo stages (incl. systemd stages) default to /etc/localtime as a file, whi...
Status: CONFIRMED
Alias: None
Product: Gentoo Release Media
Classification: Unclassified
Component: Stages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Gentoo Release Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-08-22 09:33 UTC by Michał Górny
Modified: 2024-10-18 17:00 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2024-08-22 09:33:26 UTC
According to localtime(5) (installed by systemd):

> It should be an absolute or relative symbolic link pointing to /usr/share/zoneinfo/ […]
>
> Because the timezone identifier is extracted from the symlink target name of /etc/localtime, this file may not be a normal file or hardlink.

However, in our stages (both OpenRC and systemd stages), /etc/localtime is a regular file.  And of course, since people already started assuming systemd is the golden standard, e.g. newer experimental API in libc++ throws an exception if it's not a symlink.

I think we should update it to be a symlink for the best compatibility (but I have filed a bug upstream anyway).
Comment 1 Mike Gilbert gentoo-dev 2024-08-22 16:59:11 UTC
I would not expect /etc/localtime to exist at all in stage3 tarballs. I wonder what creates it.
Comment 2 Mike Gilbert gentoo-dev 2024-08-22 17:04:12 UTC
Ah, it might be this hook in stage1:

https://gitweb.gentoo.org/proj/catalyst.git/tree/targets/stage1/preclean-chroot.sh
Comment 3 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2024-10-09 11:18:26 UTC
Gentle ping.
Comment 4 Ben Kohler gentoo-dev 2024-10-09 16:43:11 UTC
Testing with this change now:


diff --git a/targets/stage1/preclean-chroot.sh b/targets/stage1/preclean-chroot.sh
index 2dc761e9..193a12f9 100755
--- a/targets/stage1/preclean-chroot.sh
+++ b/targets/stage1/preclean-chroot.sh
@@ -15,7 +15,7 @@ setup_binutils
 if [ -d "${ROOT}/usr/share/zoneinfo" ]
 then
        rm -f "${ROOT}/etc/localtime"
-       cp "${ROOT}/usr/share/zoneinfo/Factory" "${ROOT}/etc/localtime"
+       ln -s ../usr/share/zoneinfo/Factory "${ROOT}/etc/localtime"
 else
        echo UTC > "${ROOT}/etc/TZ"
 fi
Comment 5 Larry the Git Cow gentoo-dev 2024-10-10 01:07:56 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=e574dbd24c74cedd7f59263859a6551b914410a4

commit e574dbd24c74cedd7f59263859a6551b914410a4
Author:     Ben Kohler <bkohler@gentoo.org>
AuthorDate: 2024-10-10 01:06:11 +0000
Commit:     Ben Kohler <bkohler@gentoo.org>
CommitDate: 2024-10-10 01:06:11 +0000

    targets/stage1/preclean-chroot.sh: use symlink for /etc/localtime
    
    This should be a symlink on modern systems.
    
    Bug: https://bugs.gentoo.org/938309
    Signed-off-by: Ben Kohler <bkohler@gentoo.org>

 targets/stage1/preclean-chroot.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 6 Mike Gilbert gentoo-dev 2024-10-18 15:48:19 UTC
Could we update that hook to not create any file/link at all? Having a symlink to the bogus "Factory" zone is pretty useless.

If /etc/localtime does not exist, libc and timedatedtl will default to UTC, which seems reasonable.
Comment 7 Mike Gilbert gentoo-dev 2024-10-18 16:54:11 UTC
I suppose we should check that new libc++ API to see how it handles /etc/localtime not existing at all.
Comment 8 Holger Hoffstätte 2024-10-18 17:00:01 UTC
(In reply to Mike Gilbert from comment #7)
> I suppose we should check that new libc++ API to see how it handles
> /etc/localtime not existing at all.

Make a guess :)

https://github.com/llvm/llvm-project/blob/7da0a698526ff657c2348a6e4bb835fc764177da/libcxx/src/experimental/tzdb.cpp#L727