From a6ba82fc4907891082846227a525f7c5684df2c0 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 17 Oct 2022 21:42:04 +0200 Subject: [PATCH] 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. --- Userland/Libraries/LibTimeZone/TimeZone.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibTimeZone/TimeZone.cpp b/Userland/Libraries/LibTimeZone/TimeZone.cpp index 8d3107586a..5759a0bf15 100644 --- a/Userland/Libraries/LibTimeZone/TimeZone.cpp +++ b/Userland/Libraries/LibTimeZone/TimeZone.cpp @@ -108,8 +108,8 @@ StringView current_time_zone() static constexpr auto zoneinfo = "/zoneinfo/"sv; char buffer[PATH_MAX]; - if (auto size = readlink("/etc/localtime", buffer, sizeof(buffer)); size > 0) { - StringView time_zone { buffer, static_cast(size) }; + if (realpath("/etc/localtime", buffer)) { + auto time_zone = StringView { buffer, strlen(buffer) }; if (auto index = time_zone.find(zoneinfo); index.has_value()) time_zone = time_zone.substring_view(*index + zoneinfo.length());