RFR: 8273111: Default timezone should return zone ID if /etc/localtime is valid but not canonicalization on linux [v2]
wuyan at openjdk.java.net
Thu Sep 9 08:59:08 UTC 2021
On Thu, 9 Sep 2021 08:25:44 GMT, Wu Yan <wuyan at openjdk.org> wrote:
>> Please help me review the change to enhance getting time zone ID from /etc/localtime on linux.
>> We use `realpath` instead of `readlink` to obtain the link name of /etc/localtime, because `readlink` can only read the value of a symbolic of link, not the canonicalized absolute pathname.
>> For example, the value of /etc/localtime is "../usr/share/zoneinfo//Asia/Shanghai", then the linkbuf obtained by `readlink` is "../usr/share/zoneinfo//Asia/Shanghai", and then the call of `getZoneName(linkbuf)` will get "/Asia/Shanghai", not "Asia/Shanghai", which consider as invalid in `ZoneInfoFile.getZoneInfo()`. Using `realpath`, you can get “/usr/share/zoneinfo/Asia/Shanghai“ directly from “/etc/localtime“.
> Wu Yan has updated the pull request incrementally with one additional commit since the last revision:
> replace realpath
Hi, we directly process the characters in `linkbuf` instead of realpath. And we reuse [collapse()](https://github.com/openjdk/jdk/blob/master/src/java.base/unix/native/libjava/canonicalize_md.c#L129) to process the '.' and '..' in `linkbuf`.
We tested some cases about /etc/localtime, and it works well. Test cases and results are in the attachment.
More information about the core-libs-dev