mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:57:45 +00:00
LibTimeZone: Resolve /etc/localtime with realpath(), not readlink()
On Fedora Silverblue and other OSTree-based systems, /etc/localtime is a symlink to /run/host/etc/localtime, which then points to the expected zoneinfo file, e.g. ../usr/share/zoneinfo/Europe/Berlin. By using realpath() instead of readlink() we can resolve the symlink recursively and avoid falling back to UTC.
This commit is contained in:
parent
b1b17f286f
commit
a6ba82fc49
1 changed files with 2 additions and 2 deletions
|
@ -108,8 +108,8 @@ StringView current_time_zone()
|
||||||
static constexpr auto zoneinfo = "/zoneinfo/"sv;
|
static constexpr auto zoneinfo = "/zoneinfo/"sv;
|
||||||
char buffer[PATH_MAX];
|
char buffer[PATH_MAX];
|
||||||
|
|
||||||
if (auto size = readlink("/etc/localtime", buffer, sizeof(buffer)); size > 0) {
|
if (realpath("/etc/localtime", buffer)) {
|
||||||
StringView time_zone { buffer, static_cast<size_t>(size) };
|
auto time_zone = StringView { buffer, strlen(buffer) };
|
||||||
|
|
||||||
if (auto index = time_zone.find(zoneinfo); index.has_value())
|
if (auto index = time_zone.find(zoneinfo); index.has_value())
|
||||||
time_zone = time_zone.substring_view(*index + zoneinfo.length());
|
time_zone = time_zone.substring_view(*index + zoneinfo.length());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue