HowardHinnant / date

A date and time library based on the C++11/14/17 <chrono> header
Other
3.16k stars 684 forks source link

current_zone() fails on a buildroot built target #846

Closed Julien-Blanc-tgcm closed 1 month ago

Julien-Blanc-tgcm commented 1 month ago

On our target, timezone files are found under /usr/share/zoneinfo/posix/

/usr/share/zoneinfo/ contains symlinks to `/usr/share/zoneinfo/posix/

ls -l /etc/localtime 
lrwxrwxrwx    1 root     root            32 Apr 22 10:54 /etc/localtime -> /usr/share/zoneinfo/Europe/Paris

Which should be standard

But :

# ls -l /usr/share/zoneinfo/
total 60
[snip]
lrwxrwxrwx    1 root     root            12 Dec 21  2023 Europe -> posix/Europe

This causes extract_tz_name to return posix/Europe/Paris, which is incorrect.

It seems to be related to sniff_realpath returning true, thus realpath is used instead of readlink (which would lead to the correct result).

I think the correct way to fix that is thus to alter sniff_realpath, so that it returns false for that case. It works ok for us and should not cause any regression. I'll submit a PR, unless you think there's a better fix?

HowardHinnant commented 1 month ago

Go ahead and submit the PR. That will help me study this better. Thank you for your work in diagnosing this.

Do you know why this is happening now and not years ago? Is a recent commit to blame?

Julien-Blanc-tgcm commented 1 month ago

Culprit is 9a0ee2542848ab8625984fc8cdbfb9b5414c0082 , so i would not call that a recent change. We noticed that because we updated our date library as part of standard maintenance.

On buildroot side, it seems to have used that layout for ages. I don't know why nobody noticed it before, probably not a lot of people are using your library in combination with buildroot/glibc.

I cannot test what's the result of libstdc++, as i don't have yet access to gcc13 for that target. But looking at the source code, it should be ok. I'll submit the PR next.